SHARE
TWEET

Untitled

a guest Oct 22nd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. public class Password
  3. {
  4.     public static void main(String[] args)
  5.     {
  6.         // Prompt the user to enter their password and pass their string
  7.         // to the passwordCheck method to determine if it is valid.
  8.         Scanner input = new Scanner(System.in);
  9.         System.out.println("Please enter your password");
  10.         String userPassword = input.nextLine();
  11.        
  12.         passwordCheck(userPassword);
  13.         if(passwordCheck(userPassword))
  14.         {
  15.             System.out.println("This password is valid");
  16.         }
  17.         else
  18.         {
  19.             System.out.println("This password is not valid");
  20.         }
  21.  
  22.     }
  23.    
  24.     public static boolean passwordCheck(String password)
  25.     {
  26.         // Create this method so that it checks to see that the password
  27.         // is at least 8 characters long and only contains letters
  28.         // and numbers.
  29.         boolean pass = false;
  30.        
  31.         String checker = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890";
  32.        
  33.        
  34.         for(int i = 0; i < password.length(); i++)
  35.         {
  36.             int occurrence = checker.indexOf(password.charAt(i));
  37.            
  38.             if((occurrence != -1) && password.length() >= 8)
  39.             {
  40.                 pass = true;
  41.             }
  42.             else
  43.             {
  44.                 pass = false;
  45.                 break;
  46.             }
  47.         }
  48.        
  49.        
  50.         return pass;
  51.        
  52.  
  53.     }
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. im so smart!
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top