Welcome, guest | Sign In | My Account | Store | Cart

You enter a password and the program will tell you if the the password in strong or weak. The program will also tell you how many lower and higher case letters you have and how many digits you have.

Python, 48 lines
 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
password  = 'password ' 
upperCount = 0
lowerCount = 0
digitCount = 0
strength = 0



passwordstrength = 'passwordstrength'
x = 0
while x == 0:
   userInput = raw_input ('Enter in a password: ')
   if len(userInput) < 6: # If the passowrd has less the 6 chartacter, it will say Access Denied.
        print "Not valid"

   elif len(userInput) > 12:
        print "Access Denied" # If the password is more than 12 characters, it will say Access Denied.

   else:
        print "Access Accepted" # If the password has more than 6 and less than 12 characters then th password will be accepted.
        x = 1

for password in userInput:
    if password.isupper():
        upperCount = upperCount + 1
    elif password.islower():
        lowerCount = lowerCount + 1
    elif password.isdigit():
        digitCount = digitCount + 1
print "upper case =" +str(upperCount)
print "lower case =" +str(lowerCount)
print "digits=" +str(digitCount)

if upperCount >0:
    strength = strength + 1
if lowerCount >0:
    strength = strength + 1
if digitCount >0:
    strength = strength + 1
    
if strength == 1:
    print "Weak"
  
elif strength == 2:
    print "Medium"

else:
    print "Strong"

1 comment

Dmitry Soldatov 10 years, 9 months ago  # | flag

Ugly code, no real applications for this. Letters and digits give different amount of strength. Also you should count different letters. BTW there are other languages than english. Maybe just start from wiki https://en.wikipedia.org/wiki/Password_strength

Created by superducktoxic on Mon, 8 Jul 2013 (MIT)
Python recipes (4591)
superducktoxic's recipes (5)

Required Modules

  • (none specified)

Other Information and Tasks