Skip to content

Commit b99ae73

Browse files
Merge pull request #301 from rohan37kumar/main
Created a simple Java_Password_Generator
2 parents 2fa1385 + 41f8493 commit b99ae73

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

Java_password_generator.java

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

0 commit comments

Comments
 (0)