Aug-27-2017, 03:20 PM
I have used the coding below to create a password strength checker but keep getting the upperCase variable not being recognised when I run the program. Any ideas?
[Traceback (most recent call last):
line 33, in <module>
passwordStrength = upperCase + lowerCase + digitCase
NameError: name 'upperCase' is not defined
>>>
Coding
#Test for length of password entered, check length and if outside boundaries
#say password has failed and why
incorrectPass = False
while not incorrectPass:
password = (input("Please enter a password between 6 and 12 characters"))
length = len(password)
if len (password) <6 or len(password)>12:
print ("Password needs to be between 6 and 12 characters, Password entered is only", length, "characters long")
else:
#setflag for strength test
lowerCase = 0
upperCase= 0
digitCase= 0
for ch in password:
if ch.islower():
lowerCase = 1
if ch.isupper():
upperCase= 1
if ch.isdigit():
digitCase= 1
#Strength ouput
passwordStrength = upperCase + lowerCase + digitCase
if passwordStrength ==1:
print ("This is a weak password")
elif passwordStrength ==2:
print ("This is a medium password")
if passwordStrength ==3:
print ("This is a strong password")
incorrectPass = True
[Traceback (most recent call last):
line 33, in <module>
passwordStrength = upperCase + lowerCase + digitCase
NameError: name 'upperCase' is not defined
>>>
Coding
#Test for length of password entered, check length and if outside boundaries
#say password has failed and why
incorrectPass = False
while not incorrectPass:
password = (input("Please enter a password between 6 and 12 characters"))
length = len(password)
if len (password) <6 or len(password)>12:
print ("Password needs to be between 6 and 12 characters, Password entered is only", length, "characters long")
else:
#setflag for strength test
lowerCase = 0
upperCase= 0
digitCase= 0
for ch in password:
if ch.islower():
lowerCase = 1
if ch.isupper():
upperCase= 1
if ch.isdigit():
digitCase= 1
#Strength ouput
passwordStrength = upperCase + lowerCase + digitCase
if passwordStrength ==1:
print ("This is a weak password")
elif passwordStrength ==2:
print ("This is a medium password")
if passwordStrength ==3:
print ("This is a strong password")
incorrectPass = True