Update
This commit is contained in:
1 parent
4f77adac6a
commit
4b24215279
23 files changed
+7008
-1
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SecurePasswordSpecification {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String s = sc.next();
|
||||
System.out.println(isSafePassword(s) ? "success" : "fail");
|
||||
}
|
||||
|
||||
private static boolean isSafePassword(String password) {
|
||||
if (password.length() < 6 || password.length() > 12)
|
||||
return false;
|
||||
boolean haveLower = false, hasUpper = false, haveDigit = false, hasWhitespace = false;
|
||||
for (char c : password.toCharArray()) {
|
||||
if (Character.isLowerCase(c))
|
||||
haveLower = true;
|
||||
else if (Character.isUpperCase(c))
|
||||
hasUpper = true;
|
||||
else if (Character.isDigit(c))
|
||||
haveDigit = true;
|
||||
else if (Character.isWhitespace(c))
|
||||
hasWhitespace = true;
|
||||
}
|
||||
return haveLower && hasUpper && haveDigit && !hasWhitespace;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user