Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package year_9_work;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- import java.lang.Object;
- import java.util.ArrayList;
- import java.util.Arrays;
- public class Class_PassCheck {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- while (true) {
- System.out.println
- ("1. Check Password\r\n" +
- "2. Generate Password\r\n" +
- "3. Quit.\r\n" +
- "Type Selection Number");
- int selection = scan.nextInt();
- switch (selection) {
- case 1:
- System.out.println("Enter password to be checked");
- String password = scan.nextLine();
- String StrengthQual;
- if (Check.BasicCheck(password) == true) {
- int Strength = Check.StrengthCheck(password);
- if (Strength > 20) {
- StrengthQual = "Strong";
- }
- else if (Strength <= 0) {
- StrengthQual = "Medium";
- }
- else {
- StrengthQual = "Weak";
- }
- }
- break;
- case 2:
- break;
- case 3:
- break;
- default:
- break;
- }
- }
- }
- }
- class Check {
- public static boolean BasicCheck(String password) {
- //System.out.println(ValidList);
- //if(ValidList.contains('a')) {
- // System.out.println("True");
- //}
- boolean success = true;
- String validStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!$%^&*()-_=+";
- ArrayList<Character> ValidList = (ArrayList<Character>) validStr.chars().mapToObj(c -> (char)c).collect(Collectors.toList());
- if (password.length() < 8 ) {
- System.out.println("Innapropriate password length; Too short. (min 8)");
- success = false;
- }
- else if (password.length() > 24 ) {
- System.out.println("Innapropriate password length; Too long. (max 24)");
- success = false;
- }
- else {
- boolean ascii = true;
- for(int i = 0; i < password.length(); i++) {
- if (!ValidList.contains(password.charAt(i))) {
- System.out.println("Innapropriate character used ("+password.charAt(i)+").");
- ascii = false;
- }
- }
- if (ascii = true) {
- success = true;
- }
- else {
- success = false;
- }
- }
- return success;
- }
- public static int StrengthCheck(String password) {
- int Strength = password.length();
- String UpperStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- ArrayList<Character> UpperList = (ArrayList<Character>) UpperStr.chars().mapToObj(c -> (char)c).collect(Collectors.toList());
- String LowerStr = "abcdefghijklmnopqrstuvwxyz";
- ArrayList<Character> LowerList = (ArrayList<Character>) LowerStr.chars().mapToObj(c -> (char)c).collect(Collectors.toList());
- String NumStr = "0123456789";
- ArrayList<Character> NumList = (ArrayList<Character>) NumStr.chars().mapToObj(c -> (char)c).collect(Collectors.toList());
- String SymStr = "!$%^&*()-_=+";
- ArrayList<Character> SymList = (ArrayList<Character>) SymStr.chars().mapToObj(c -> (char)c).collect(Collectors.toList());
- String QwertyStr = "qwertyuiopasdfghjklzxcvbnm";
- int[] QposArr = new int[password.length()];
- boolean Lower = false; boolean Upper = false; boolean Numb = false; boolean Symb = false;
- for (int i = 0; i < password.length(); i++) {
- if (UpperList.contains(password.charAt(i))) {
- Upper = true;
- }
- if (LowerList.contains(password.charAt(i))) {
- Lower = true;
- }
- if (NumList.contains(password.charAt(i))) {
- Numb = true;
- }
- if (SymList.contains(password.charAt(i))) {
- Symb = true;
- }
- QposArr[i] = QwertyStr.indexOf(Character.toLowerCase(password.charAt(i)));
- }
- if (Lower) {
- Strength+=5;
- System.out.println("Lower Case Used (+5). Total = "+Strength);
- }
- if (Upper) {
- Strength+=5;
- System.out.println("Upper Case Used (+5). Total = "+Strength);
- }
- if (Numb) {
- Strength+=5;
- System.out.println("Number Used (+5). Total = "+Strength);
- }
- if (Symb) {
- Strength+=5;
- System.out.println("Symbol Used (+5). Total = "+Strength);
- }
- if (Lower && Upper && Numb && Symb) {
- Strength+=10;
- System.out.println("All Character Types (+10). Total = "+Strength);
- }
- if ((Lower||Upper)&&!(Numb&&Symb)) {
- Strength-=5;
- System.out.println("Only Letters (-5). Total = "+Strength);
- }
- if ((Symb)&&!(Lower||Upper||Numb)) {
- Strength-=5;
- System.out.println("Only Symbols (-5). Total = "+Strength);
- }
- if ((Numb)&&!(Lower||Upper||Symb)) {
- Strength-=5;
- System.out.println("Only Numbers (-5). Total = "+Strength);
- }
- for (int i = 2; i < QposArr.length; i++) {
- if (((QposArr[i]-1)==(QposArr[i-1]))&&((QposArr[i-1]-1)==(QposArr[i-2]))) {
- Strength-=5;
- System.out.println("String of Adjacent characters from QWERTY ("+QwertyStr.charAt(QposArr[i-2])+QwertyStr.charAt(QposArr[i-1])+QwertyStr.charAt(QposArr[i-3]));
- }
- }
- return Strength;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement