Skip to content

Commit ce20ac2

Browse files
authored
Merge pull request #661 from RC2208/master
Check Password strength
2 parents 3786994 + c1f0b4b commit ce20ac2

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#program to check password strength. A strong password needs to be at least 8 chars long, have both upper and lowercase chars and have some special characters as well.
2+
import string
3+
4+
def Strength(password):
5+
6+
n = len(password)
7+
8+
hasLower = False
9+
hasUpper = False
10+
hasDigit = False
11+
specialChar = False
12+
p = string.ascii_letters + string.digits #contains all alphabets(in lower & upper case) and digits (0-9)
13+
14+
for i in range(n):
15+
if password[i].islower():
16+
hasLower = True
17+
if password[i].isupper():
18+
hasUpper = True
19+
if password[i].isdigit():
20+
hasDigit = True
21+
if password[i] not in p:
22+
specialChar = True
23+
24+
# Strength of password calculation.
25+
26+
print("Strength of password:-", end = "")
27+
if (hasLower and hasUpper and
28+
hasDigit and specialChar and n >= 8):
29+
print("Strong")
30+
31+
elif ((hasLower or hasUpper) and
32+
specialChar and n >= 6):
33+
print("Moderate")
34+
else:
35+
print("Weak")
36+
37+
38+
if __name__=="__main__":
39+
40+
password = input("Enter password: ")
41+
42+
Strength(password)

0 commit comments

Comments
 (0)