Advertisement
MariiaMuzykantova

Untitled

Nov 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class StringPasswordStrength {
  4.  
  5. public static void main(String[] args) {
  6. Scanner reader = new Scanner(System.in);
  7. System.out.print("Enter password: ");
  8. String password = reader.nextLine();
  9.  
  10. if (strongEnough(password) == true) {
  11. System.out.print("OK");
  12. } else {
  13. System.out.print("Not strong enough!");
  14. }
  15. reader.close();
  16. }
  17.  
  18. private static boolean strongEnough(String a) {
  19. if (a.matches("^((?=.*[A-Z])(?=.*[a-z])(?=.*\\d)|(?=.*[a-z])(?=.*\\d)"
  20. + "(?=.*[^0-9A-Za-z])|(?=.*[A-Z])(?=.*\\d)(?=.*[^0-9A-Za-z])|(?=.*[A-Z])"
  21. + "(?=.*[a-z])(?=.*[^0-9A-Za-z])).{8,}$")) {
  22. return true;
  23. } else {
  24. return false;
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement