#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    1

    Limiting Letters in a String


    Why is this code letting me enter a password such as abc123?

    Code:
                    System.out.println("\nEnter new password:");
                    strPasswordTemp = input.next();
                    byte[] bytPassword = strPasswordTemp.getBytes();  
                    for (byte bytTemp : bytPassword)
                    {
                        char tempChar = (char) bytTemp;
                        if (Character.isLetter(tempChar))
                        {
                            intNumOfLetters++;
                        } // end of if statement
                        if (Character.isDigit(tempChar))
                        {
                            intNumOfDigits++;
                        } // end of if statement
                    } // end of for loop
                    if (intNumOfLetters < 8 && intNumOfDigits < 3)
                    {
                        System.out.println("\n[ Password must contain at least 8 " +
                            "letters and 3 numbers ]");
                        System.out.println("\nPlease press the 'Enter' key to " +
                                "continue");
                        keyIn.nextLine();
                        break;
                    } // end of if statement
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    1
    It was because I used && instead of ||

IMN logo majestic logo threadwatch logo seochat tools logo