Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

re: username and password

843807Jun 9 2010 — edited Jun 19 2010
Used code tags this time. Ya so i was wondering about how to input a username and make it go together with a password.

my frame looks like

Username: ____
Password:______

so i have labels and text fields just need to know how to incorporate them.

I tried the same concept as the password by creating a boolean and setting the correct name but in the actionperformed when i .getText from user input it gives me an error. For the password .getPassword(im using a JPasswordField) it works. Any Ideas
public void actionPerformed( ActionEvent evt)
  {
      {
        String cmd = evt.getActionCommand();
        String text = evt.getActionCommand();
    if(name.equals(text))
    {
         //here is the error(menutextname is the JTextField)
        char[] input = menutextname.getText();
    }

    if (password.equals(cmd))
    { //Process the password.
        
        char[] input = menupasswordtext.getPassword();
        if (isPasswordCorrect(input))
        {
          options();
          menuframe.setVisible(false);
        }
        else {
            JOptionPane.showMessageDialog(menuframe,
                "Invalid password. Try again.",
                "Error Message",
                JOptionPane.ERROR_MESSAGE);
        }
     }
      }

      if(evt.getActionCommand().equals("New BS"))//if the action equals 'new game'
    {
        BS();
        optionframe.setVisible(false);
    }
  }
  
private static boolean isNameCorrect(char[] input)
  {
      boolean isCorrect= true;
      char[] correctname = {'b','o','b'};
      if (input.length!=correctname.length)
      {
          isCorrect=false;
      }
      else
      {
         isCorrect = Arrays.equals (input, correctname) ;
      }
      Arrays.fill(correctname,'0');
      return isCorrect;
  }
  
private static boolean isPasswordCorrect(char[] input)
  {
    boolean isCorrect = true;
    char[] correctPassword = { 'p', 'a', 's', 's', 'w', 'o', 'r','d' };
    if (input.length != correctPassword.length) {
        isCorrect = false;
    } else {
        isCorrect = Arrays.equals (input, correctPassword);
    }

    //Zero out the password.
    Arrays.fill(correctPassword,'0');

    return isCorrect;
  }

}
Edited by: babojee on Jun 9, 2010 7:42 PM

Edited by: babojee on Jun 9, 2010 8:30 PM

Edited by: babojee on Jun 9, 2010 8:35 PM

Comments

843807
...in the actionperformed when i .getText from user input it gives me an error
What does this mean? Error codes would be nice to have and a complete description would also be very helpful.
843807
this line:
char[] input = menutextname.getText();
gives me and error.

basically what im trying to do is create a username and password

if u have any other way of doing the username and password id like to hear it

Edited by: babojee on Jun 10, 2010 3:51 AM
843807
char[] input = menutextname.getText();
Just to finish out your idea...
char[] input = menutextname.getText().toCharArray();
Do you read the API? getText returns String you are asking for an array of chars, if you look in the String API, guess what: it shows toCharArray().
843807
thank you, sorry for the trouble
843807
No trouble, it's just intersting seeing how many people don't read the free documentation available.
843807
srry i never knew about it and im in school and my teacher is like here's a major project, oh and btw u have to learn GUI by yourself and create a program for a client. Useless teachers these days.

one more thing about the username and password

say it the user wants to change it

so i have

old password:

new password:

save(button)

so i was thinking about it as getting the user input just the same as before when the user logins in and getting the users input for new password and then storing/saving into in the char passwordCorrect ( 's'). but the problem with me is i understand it but when i translate it into code it just comes out ................blah.

Edited by: babojee on Jun 11, 2010 12:53 AM
darrylburke
babojee wrote:
srry i never knew about it and im in school and my teacher is like here's a major project, oh and btw u have to learn GUI by yourself and create a program for a client. Useless teachers these days.
Certainly your teachers didn't teach you that every sentence starts with a capital letter, or how to spell words like "sorry" "I'm" "you" or that the first person singular is written with a capital I.

It's not your fault, your teachers are to be blamed... or not?

db
843807
lol nah he taught nothing at all.

also i know how to spell its just when i type on a computer i use abbreviations.

If I do formal typing I will type properly.
User_64CKJ
babojee wrote:
lol nah he taught nothing at all.

also i know how to spell its just when i type on a computer i use abbreviations.

If I do formal typing I will type properly.
Be warned that you are on the express train to 'being ignored for your laziness' if you do not take the time to type properly. If you cannot expend the effort to type properly, why should we expend the effort to wade through such dross?
843807
OK, I'm sorry about that then I just assumed that everyone knows that people type with abbreviations on the internet. It isn't laziness, it is just the way of typing on the internet. If you want me to type properly to you I will then. Now back to my question you guys got any ideas?
843807
babojee wrote:
OK, I'm sorry about that then I just assumed that everyone knows that people type with abbreviations on the internet. It isn't laziness, it is just the way of typing on the internet. If you want me to type properly to you I will then. Now back to my question you guys got any ideas?
This isn't my business but, [expletive-deleted]. That is not "just the way of typing on the internet". That is the way of ignorance and laziness. How can you ever expect to be successful in writing code when you fail to type conversational English? Whenever I see "srry", "plz", etc I assume the individual behind the keys is either under the age of 15 or has the mental capacities as such. And to hopefully avoid being berated:
PseudoCode:
if (oldPassword.equals(originalPassword)) {
  originalPassword = newPassword;
} else {
  fail;
}
1 - 11
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 17 2010
Added on Jun 9 2010
11 comments
1,165 views