Advertisement
MladenPetrov

Untitled

Oct 15th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class passValidatorNew {
  4.     private static void checkPassword(String input) {
  5.         int positiveCount = 0;
  6.         if (input.length() < 6 || input.length() > 11) {
  7.             System.out.println("Password must be between 6 and 10 characters");
  8.         } else {
  9.             positiveCount++;
  10.         }
  11.  
  12.  
  13.         int count = 0;
  14.         for (int i = 0; i < input.length(); i++) {
  15.             int currentNumber = input.charAt(i);
  16.             if (currentNumber < 48 || currentNumber > 57 && currentNumber < 65 || currentNumber > 90 && currentNumber < 97 || currentNumber > 122) {
  17.                 count++;
  18.             }
  19.         }
  20.         if (count > 0) {
  21.             System.out.println("Password must consist only of letters and digits");
  22.         } else {
  23.             positiveCount++;
  24.         }
  25.  
  26.  
  27.         int countNumber = 0;
  28.         for (int i = 0; i < input.length(); i++) {
  29.             int currentNumber = input.charAt(i);
  30.             if (currentNumber >= 48 && currentNumber <= 57) {
  31.                 countNumber++;
  32.             }
  33.         }
  34.         if (countNumber < 2) {
  35.             System.out.println("Password must have at least 2 digits");
  36.         } else {
  37.             positiveCount++;
  38.         }
  39.  
  40.         if (positiveCount >= 3) {
  41.             System.out.println("Password is valid");
  42.         }
  43.  
  44.     }
  45.  
  46.  
  47.  
  48.  
  49.     public static void main(String[] args) {
  50.         Scanner scanner = new Scanner(System.in);
  51.  
  52.         String input = scanner.nextLine();
  53.  
  54.         checkPassword(input);
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement