In: Computer Science
Write a Java method to check whether a string is a valid password.
Password rules:
A password must have at least ten characters.
A password consists of only letters and digits.
A password must contain at least two digits.
There are at least SIX functions/methods as the following:
1. menu() – to print the password’s rules.
2. getString() – to get the password from the user.
3. isPassword() – to check either the password is valid based on the given rules. 4
. getChar() - to get the input from the user, either ‘y’ or ‘n’.
5. isLetter() – to check the password to be a letter from ‘A’ to ‘Z’.
6. isNumric() – to check the password to be a number from ‘0’ to ‘9’.
fprintf("1.A password must have
at least eight characters.\n") fprintf("2.A password consists of
only letters and digits.\n") fprintf("3.A password must contain at
least two digits .\n") password=input("Input a password (You are
agreeing to the above Terms and conditions.):",'s');
len= length (password);
valid=true;
if len<8 valid=false; else digit_count =0; for i= 1:len ch=password (i);. if ch>='0'&&ch<='9' digit_count=digit_count+
1; elseif(ch<'a' II ch>'z') &&. (ch<'A' II ch>'z') valid=false; end end if digit_count<2 valid =false; end end
if valid printf("password is valid :%S\n", password). else. printf("password is invalid:%S\n", password) end