0
Trying to figure this out. Learning in Java and not sure how to code this
Write a program that prompts the user to enter a password and displays Valid Password if the rules are followed or Invalid Password other wise. 1. A Password must have at least eight characters. 2. A Password consists of only letters and digits. 3. A Password must contain at least two digits. Write a method that checks whether a string is a valid password.
2 Réponses
+ 13
● take the input as String str
● make a method which returns true if all conditions satify
● rough structure of method
1) str.length() == 8
//if true then continue to 2) else return false
2) then check for number of digits
//use ASCII value for it , also count number of digit there using a counter variable
//if number of digits >=2 then continue to 3) else returnfalse
3) now run loop again on that String & check for 8-(number if digits) must be the number of alphabets
//return true if 3) also return returns true , else false
//check out this ASCII code for getting idea of range to be used for alphabets & digits
https://code.sololearn.com/c92zC0xH0AHv/?ref=app
0
you also can use specific regular expressions for checking.
For example:
String expr ="expression";
Pattern patt = Pattern.compile(expr);
Matcher m = patt.matcher("some string");
then you can get boolean value wich you can check in condition block if(){}
boolean b = matcher.matches();
you can look example of using in following code:
https://code.sololearn.com/ci5m428JvUf9/?ref=app