Advertisement
jwrbg

асд

Mar 5th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.83 KB | None | 0 0
  1. package TechModule;
  2.  
  3.         import java.util.Scanner;
  4.  
  5. public class p03_MethodsPasswordValidator {
  6.  
  7.     public static boolean isSymbol(String password, int a){
  8.         boolean isSymbol=false;
  9.         for (int i = 0; i < a; i++) {
  10.             if ((password.charAt(i) >= 65 && password.charAt(i) <= 90)
  11.                     ||(password.charAt(i) >= 97 && password.charAt(i) <= 122)
  12.                     ||(password.charAt(i) >= 48 && password.charAt(i) <= 57)){
  13.                 isSymbol = true;
  14.             } else {
  15.                 isSymbol=false;
  16.                 break;}
  17.         }
  18.         return isSymbol;}
  19.  
  20.  
  21.  
  22.  
  23.     public static void main(String[] args) {
  24.         Scanner scanner = new Scanner(System.in);
  25.         String password = scanner.nextLine();
  26.         int count = 0;
  27.         boolean isDigit = false;
  28.         boolean passwordCharacters = true;
  29.  
  30.         boolean symbol=isSymbol(password, password.length());
  31.  
  32.         if (password.length() > 10 || password.length() < 6) {
  33.             System.out.println("Password must be between 6 and 10 characters");
  34.             passwordCharacters = false;
  35.         }
  36.         for (int i = 0; i < password.length(); i++) {
  37.             if (password.charAt(i) >= 48 && password.charAt(i) <= 57) {
  38.                 count++;
  39.                 isDigit = true;
  40.             }
  41.  
  42.         }
  43.  
  44.         if (symbol == false) {
  45.             System.out.println("Password must consist only of letters and digits");
  46.         }
  47.         if (count <= 2) {
  48.             System.out.println("Password must have at least 2 digits");
  49.         }
  50.         if (passwordCharacters && isDigit && symbol==true) {
  51.             System.out.println("Password is valid");
  52.         }
  53.  
  54.  
  55.     }
  56.  
  57.  
  58. }
  59. --------------------------------------------------------------------------------------------------------------------------
  60. сетих се ,че мога да превърна всички букви в малки примерно и да премахна проверката за големи букви... обаче, още някъде бъркам ... ???
  61.  
  62. ----------------------------------------------------------------------------------------
  63. Write a program that checks if a given password is valid. Password rules are:
  64. 610 characters (inclusive)
  65. • Consists only of letters and digits
  66. • Have at least 2 digits
  67. If a password is valid print “Password is valid”. If it is not valid, for every unfulfilled rule print a message:
  68. "Password must be between 6 and 10 characters"
  69. "Password must consist only of letters and digits"
  70. "Password must have at least 2 digits"
  71. Examples
  72. Input   Output
  73. logIn   Password must be between 6 and 10 characters
  74. Password must have at least 2 digits
  75. MyPass123   Password is valid
  76. Pa$s$s  Password must consist only of letters and digits
  77. Password must have at least 2 digits
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement