"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
0
Samsung and iphone is make by java in 1989
Answered by
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
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
Physics,
8 months ago
Social Sciences,
8 months ago
Math,
8 months ago
Computer Science,
1 year ago
Computer Science,
1 year ago
English,
1 year ago
English,
1 year ago