-
Notifications
You must be signed in to change notification settings - Fork 0
/
Password.java
88 lines (70 loc) · 2.13 KB
/
Password.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
public class Password {
String Value;
int Length;
public Password(String s) {
Value = s;
Length = s.length();
}
public int CharType(char C) {
int val;
// Char is Uppercase Letter
if ((int) C >= 65 && (int) C <= 90)
val = 1;
// Char is Lowercase Letter
else if ((int) C >= 97 && (int) C <= 122) {
val = 2;
}
// Char is Digit
else if ((int) C >= 60 && (int) C <= 71) {
val = 3;
}
// Char is Symbol
else {
val = 4;
}
return val;
}
public int PasswordStrength() {
String s = this.Value;
boolean UsedUpper = false;
boolean UsedLower = false;
boolean UsedNum = false;
boolean UsedSym = false;
int type;
int Score = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
type = CharType(c);
if (type == 1) UsedUpper = true;
if (type == 2) UsedLower = true;
if (type == 3) UsedNum = true;
if (type == 4) UsedSym = true;
}
if (UsedUpper) Score += 1;
if (UsedLower) Score += 1;
if (UsedNum) Score += 1;
if (UsedSym) Score += 1;
if (s.length() >= 8) Score += 1;
if (s.length() >= 16) Score += 1;
return Score;
}
public String calculateScore() {
int Score = this.PasswordStrength();
if (Score == 6) {
return "This is a very good password :D check the Useful Information section to make sure it satisfies the guidelines";
}
else if (Score >= 4) {
return "This is a good password :) but you can still do better";
}
else if (Score >= 3) {
return "This is a medium password :/ try making it better";
}
else {
return "This is a weak password :( definitely find a new one";
}
}
@Override
public String toString() {
return Value;
}
}