File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ import string
2
+
3
+ def Strength (password ):
4
+
5
+ n = len (password )
6
+
7
+ hasLower = False
8
+ hasUpper = False
9
+ hasDigit = False
10
+ specialChar = False
11
+ p = string .ascii_letters + string .digits #contains all alphabets(in lower & upper case) and digits (0-9)
12
+
13
+ for i in range (n ):
14
+ if password [i ].islower ():
15
+ hasLower = True
16
+ if password [i ].isupper ():
17
+ hasUpper = True
18
+ if password [i ].isdigit ():
19
+ hasDigit = True
20
+ if password [i ] not in p :
21
+ specialChar = True
22
+
23
+ # Strength of password calculation.
24
+ # password is strong only if it has both upper case and lowercase letters as well as special characters.
25
+ # Also length should be greater than or equal to 8
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 )
You can’t perform that action at this time.
0 commit comments