Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24

Thread: Password asking

  1. #21
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    No. First let's make your test password smaller (let's not make this too hard on ourselves), for example to take your code:

    Java Code:
      private static boolean CheckPswd(char[] pswd) {
        boolean isCorrect = true;
        char[] p1 = { 'F', 'u' };
        char[] p2 = { 'B', 'a', 'r' };
        char[][] pass = { p1, p2 };
        int i = 1;
        isCorrect = false;
        while (i > pass.length) {
          while (!isCorrect) {
            if (pswd.length != pass.length) {
              isCorrect = false;
            } else {
              isCorrect = Arrays.equals(pswd, pass[i]);
            }
          }
          i++;
        }
        Arrays.fill(pass[0], '0');
        Arrays.fill(pass[1], '0');
        return isCorrect;
      }
    then imagine that you're going to call CheckPswd() method on {'F', 'u'}
    then step through each line of code noting on paper what the values of variables should be. I'll leave out pass here because we should know what it is.

    pswd = {'F', 'u'}
    int i = 1; i is now 1
    isCorrect = false; isCorrect is false
    while (i > pass.length) means while (1 > 2) OK this bumps me out incorrectly

    Then fix this problem and again walk through your code line by line thinking on what the value of each variable. Do the loops too. Leave no stone unturned.

    Then do the same thing but for input of {'b', 'a', 'z'} to see if the code catches the incorrect password here.

  2. #22
    Kruptein is offline Member
    Join Date
    Aug 2009
    Posts
    32
    Rep Power
    0

    Default

    OKay I did it like you asked:

    Now it only says Login Succesfull if I type Passwore, but if I type Password it still says Login Fails.

    (suppose you fill in the passwordfield: Pass)
    Java Code:
            char[] p1 = {'P', 'a', 's', 's', 'w', 'o', 'r', 'd'};
            char[] p2 = {'P', 'a', 's', 's', 'w', 'o', 'r', 'e'};
            char[][] pass = {p1,p2};
            int i = 1;                   // i = 1
            int j = 0;                  // j = 0
            isCorrect = false;          //  isCorrect = false
            while(i <= pass.length){   //   while(1 <= 2){
                if(pswd.length != pass[j].length) {  // if( 4 != 8){
                    isCorrect = false;              // isCorrect = true;
                }else{
                    isCorrect = Arrays.equals(pswd, pass[j]); // isCorrect = true
                }
                i++;  // i = 2
                j++;  //j = 1
            }
    Last edited by Kruptein; 08-18-2009 at 01:25 PM.

  3. #23
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Hm, this works for me:
    Java Code:
      private static boolean CheckPswd(char[] pswd) {
        char[] p1 = {'P', 'a', 's', 's', 'w', 'o', 'r', 'd'};
        char[] p2 = {'P', 'a', 's', 's', 'w', 'o', 'r', 'e'};
        char[][] pass = {p1,p2};
        int j = 0;
        boolean isCorrect = false;
        while (j < pass.length && !isCorrect ) {
          char[] password = pass[j];
          if (password.length == pswd.length) {
            isCorrect = Arrays.equals(password, pswd);
          }
          j++;
        }
        return isCorrect;
      }
    But seriously, I wouldn't fiddle with any of this stuff. If I wanted a password, I'd Google on how to do passwords, security, and encryption with Java.

  4. #24
    Kruptein is offline Member
    Join Date
    Aug 2009
    Posts
    32
    Rep Power
    0

    Default

    If I use that together with messagedigest,

    why would it be bad?

Page 2 of 2 FirstFirst 12

Similar Threads

  1. 'Password' help
    By iWonder in forum New To Java
    Replies: 20
    Last Post: 12-17-2008, 10:05 PM
  2. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum New To Java
    Replies: 2
    Last Post: 11-14-2008, 07:53 PM
  3. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum Java Servlet
    Replies: 0
    Last Post: 11-14-2008, 01:22 PM
  4. How to check password of a jsp/html with the password of Database(mysql) #1
    By sk.mahaboobbhasha@gmail.c in forum Java Servlet
    Replies: 2
    Last Post: 11-14-2008, 01:11 PM
  5. How to get password in SWT
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-02-2008, 08:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •