Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8680907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:22:07+00:00 2026-06-12T21:22:07+00:00

I have a properties file that holds username and password which I use in

  • 0

I have a properties file that holds username and password which I use in my java program however I am not being able to store more than one username and password like I do in database and just select where username and password match the many rows in the database. I imagine I need to have a two-dimensional array stored in the file holding usernames and corresponding passwords but I’ve failed to figure out how to do it and neither has google given me a way to hold a two-dimensional array in a file yet. Here are the key/value pairs for my username and password in the file

    `password=k
     username=k`

And here is the code that reads them and compares with what the user inserts

   `String usr = userfield.getText();
    String pwd = new String(pwdfield.getPassword());
    Properties config = new Properties();
    InputStream is;

    try {

        is = new FileInputStream("config.properties");
        config.load(is);

        if (usr.toString().equals(config.getProperty("user").toString()) && pwd.toString().equals(config.getProperty("pass").toString())) {
            new DocMenu();
            lgFrame.dispose();

        } else {
            JOptionPane.showMessageDialog(lgFrame, "Wrong credentials try again", "Oops", JOptionPane.ERROR_MESSAGE);

        }

        is.close();

    } catch (Exception ex) {
        System.out.println(ex);
        ex.printStackTrace();
    }`

Could someone please tell me how to change the properties file and the code so that I am able to have multiple usernames and passwords in the file to grant access to any user as long as their username and password exist.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:22:09+00:00Added an answer on June 12, 2026 at 9:22 pm

    If you store the property name as a concatenation of some key with the username, and the password as the value like this;

    #Some bad passwords
    username.bob=password
    username.scott=tiger
    username.admin=admin
    

    ..then you can check like this;

    String password = config.getProperty("username." + usr.toString());
    if (password != null && password.equals(pwd.toString())) {
      new DocMenu();
      lgFrame.dispose();
    } else {
      JOptionPane.showMessageDialog(lgFrame, "Wrong credentials try again", "Oops", JOptionPane.ERROR_MESSAGE);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hibernate.properties file that holds all the hibernate properties for my application.
I have a properties file, let say my-file.properties. In addition to that, I have
I have an f:loadBundle that loads a properties file from my classpath. <f:loadBundle basename=com.xxx.ui.messages
I have an executable jar Client.jar that requires jndi.properties file. Since the jndi properties
I have a properties file which currently contains system names and ip addresses. What
I have a java app, and the log4j.properties file is in src/com/my/path/props. On compile,
see i have one PROPERTIES File now i have to write a program for
I have an application that uses a properties file that was added by hand
I have a properties file that contains a property specifying the URL of a
I have a properties file that says window.1.height=100 window.1.width=80 window.2.height=50 window.2.width=30 window.3.height=150 window.3.width=100 I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.