Computer Science, asked by abenrs9642, 1 year ago

"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. input: pass1234 output valid input: pass#123 output:notvalid"

Answers

Answered by anurag219
0
Samsung and iphone is make by java in 1989
Answered by digi18
4
Here is your function for checking password.

pubic void checkPassword () {

Scanner sc=new Scanner(System.in);       

System.out.println ("Enter password");

String pwd = sc.next ();

if (! (pwd.length == 10)) {

System.out.println("Password is short");

}

else if ("pwd.isdigit () < 2") {

System.out.println("Password should have atleast 2 digits");

}

else {

Pattern p = Pattern.compile ("[a-zA-Z0-9]");
Matcher m = p.matcher (pwd);
boolean b = m.find();

if (b) {

System.out.println("Invalid password");

}

else {

System.out.println("Valid password");

}

}

}

Thanks
Similar questions