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 7698815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:19:50+00:00 2026-05-31T22:19:50+00:00

I’ve created a user login dialog box that compares the user’s name and password

  • 0

I’ve created a user login dialog box that compares the user’s name and password that they have stored in a csv file to what they have typed within corresponding textfields. Before the login appears, I’ve used JOptionPanes to display the return statements that I’ve passed the username name password into. The JOptionPane displays the name and password. But after I login appears, then enter the name and password to compare to, login is not successful. When I used JOptionPane to display the same username and password again, it says both are null. I’ve narrowed down the problem where I’ve setup a seperate boolean method that I use to see if what the user enters is equal to the return method’s value are, but for some reason, my return methods returns to NULL before comparing.

Any suggestions as to why this is happening? Again, for some reason, I’m losing the return values of “getName()” and “getPass().”

/**Read csv data. put data into array, then elements into variables */
    String lines = "";
    String unparsedFile = "";

    FileReader fr = new FileReader("c:\\foo\\user.dat");
    BufferedReader br = new BufferedReader(fr);

    while((lines = br.readLine()) != null){
        unparsedFile += lines;
    }

    br.close();
    userData = unparsedFile.split(",");
    String g = userData[0];

    g1 = userData[0]; // return in String method "getName()"
    this.name = g1;

    h1 = userData[1]; // returned in String method "getPass()"
    this.password = h1; 
///////////////////////////////
/* check if what you entered is same as getName() and getPass() */
public static boolean authenticate(String username, String password){

    String g2, h2;
    g2 = cn.getName();
    h2 = cn.getPass();
    JOptionPane.showInputDialog(null, cn.getName() + " login " + cn.getPass());
    if(username.equals(g2) && password.equals(h2)){
        JOptionPane.showInputDialog(null, "True");
        return true;
    }
    JOptionPane.showInputDialog(null, cn.getName() + " login false " + cn.getPass());
    return false;
}
////////////////////////
/* Login: enter name and password, the check if it matches getName() and getPass() */
nam = tfUsername.getText();
        passA = pfPassword.getText();

            if(Login.authenticate(nam, passA)){
                JOptionPane.showMessageDialog(UserLogin.this,
                        "Welcome, " + cn.getChatName() + ". Login successful.",
                        "Login",
                        JOptionPane.INFORMATION_MESSAGE);
                        succeeded = true;
                        dispose();
            }
            if(!nam.equals(cn.getName()) && !passA.equals(cn.getPass())){
                JOptionPane.showMessageDialog(UserLogin.this, "Invalid username or password",
                        "Login unsuccessful", JOptionPane.ERROR_MESSAGE);
                //reset username and password
                tfUsername.setText("");
                pfPassword.setText("");
                succeeded = false;
            }
        }   
    });
  • 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-05-31T22:19:51+00:00Added an answer on May 31, 2026 at 10:19 pm

    Given that the following works fine

    public class PasswordData {
        private String _password;
        private String _username;
    
        public PasswordData(String password, String username)
        {
            _password = password;
            _username = username;
        }
    
        public String getUsername()
        {
            return _username;
        }
    
        public void setUsername(String username)
        {
            _username = username;
        }
    
        public String getPassword()
        {
            return _password;
        }
    
        public void setPassword(String password)
        {
            _password = password;
        }
    }
    
    public class StackOverflowPasswordExample {
        private static PasswordData cn;
    
        public static void main(String[] args) {
            cn = new PasswordData("mypassword", "myusername");
            boolean auth = authenticate();
            System.out.println("authenticated is " + auth);
        }
    
        public static boolean authenticate() { 
            String g2 = cn.getPassword();
            String h2 = cn.getUsername(); 
    
            return g2 != null && h2 != null;
        } 
    
    }
    

    You have not provided enough information, we need the set code, update code because it is almost definately there the issue is (is cn the instance you think it is for example or has it been overwritten)

    as it stands I cannot help further until you provide a shorter example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.