Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Password
- {
- public static void main(String[] args)
- {
- // Prompt the user to enter their password and pass their string
- // to the passwordCheck method to determine if it is valid.
- Scanner input = new Scanner(System.in);
- System.out.println("Please enter your password");
- String userPassword = input.nextLine();
- passwordCheck(userPassword);
- if(passwordCheck(userPassword))
- {
- System.out.println("This password is valid");
- }
- else
- {
- System.out.println("This password is not valid");
- }
- }
- public static boolean passwordCheck(String password)
- {
- // Create this method so that it checks to see that the password
- // is at least 8 characters long and only contains letters
- // and numbers.
- boolean pass = false;
- String checker = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890";
- for(int i = 0; i < password.length(); i++)
- {
- int occurrence = checker.indexOf(password.charAt(i));
- if((occurrence != -1) && password.length() >= 8)
- {
- pass = true;
- }
- else
- {
- pass = false;
- break;
- }
- }
- return pass;
- }
- }
- im so smart!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement