0

The task was to create a Java program to check if a password is valid. The criteria involved: - Has 6 characters - Starts with a letter

I also need to test the password to see if valid and display a message saying. "valid password" or "invalid password

  for(int i = 0; i < password.length();i++)
{
    char ch = password.charAt(i); //checks if charachter is letter or digit
    if (Character.isLetter(ch))
    {
        num++;
    }
    else
    {
        let++;

    }

}   
txaDisplay.append("Number of Letters:"+let);
txaDisplay.append("\n Number of Digits:"+num);


char valid = password.charAt(0);
if (Character.isLetter(valid))
    {
        num++;
    }
    else
    {
        let++;

    }
txaDisplay.append("Password is valid");
txaDisplay.append("Password is invalid");
rubin.kazan
  • 131
  • 12

1 Answers1

0

To validate password regular expression would be a better option please check with this

Community
  • 1
  • 1
The N..
  • 70
  • 1
  • 5