Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class password {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         System.out.print("Придумайте пароль");
  10.         Scanner scan = new Scanner(System.in);
  11.         String pass = scan.nextLine();
  12.  
  13.         test(pass);
  14.  
  15.     }
  16.  
  17.     public static boolean checknumbers(String str) {
  18.  
  19.         Pattern p = Pattern.compile("^.*\\d.*$");
  20.  
  21.         Matcher m = p.matcher(str);
  22.  
  23.         return m.matches();
  24.     }
  25.  
  26.     public static boolean checkSize(String str) {
  27.         Pattern p = Pattern.compile("^.{8,15}$");
  28.         Matcher m = p.matcher(str);
  29.  
  30.         return m.matches();
  31.     }
  32.  
  33.     public static boolean checkcapital(String str) {
  34.  
  35.         Pattern p = Pattern.compile("^.*[A-Z ].*$");
  36.  
  37.         Matcher m = p.matcher(str);
  38.  
  39.         return m.matches();
  40.  
  41.     }
  42.  
  43.     public static boolean checkSymbols(String str) {
  44.  
  45.         Pattern p = Pattern.compile("^.*[!, №, #, %, ^, &, *, @, $].*$");
  46.  
  47.         Matcher m = p.matcher(str);
  48.  
  49.         return m.matches();
  50.  
  51.     }
  52.  
  53.     public static boolean test(String str) {
  54.  
  55.         boolean f = false;
  56.  
  57.         if (checknumbers(str) == true) {
  58.             f = true;
  59.         } else {
  60.             System.out.println("Пароль должен содержать хотя бы одну цифпу");
  61.             f = true;
  62.         }
  63.  
  64.         if (checkSize(str) == true) {
  65.  
  66.         } else {
  67.             System.out.println("Пароль должен быть не короче 8 символов и не длинее 15");
  68.             f = false;
  69.         }
  70.  
  71.         if (checkcapital(str) == true) {
  72.  
  73.         } else {
  74.             System.out.println("Должна быть хоть 1 Заглавный символ");
  75.             f = false;
  76.         }
  77.  
  78.         if (checkSymbols(str) == true) {
  79.  
  80.         } else {
  81.             System.out.println("Должен быть миними 1 спец. символ");
  82.         }
  83.  
  84.         return f;
  85.  
  86.     }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement