Python Forum
Variable not defined in password checker
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variable not defined in password checker
#1
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
Reply
#2
Please use proper indentation and formatting. I had to indent your code and it works just fine.

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
Reply
#3
Thank you for such a prompt reply
The code works as long as you put the password between 6 and 12 words but when you put
a password of say 3 characters the while loop does not work as it goes straight to the error message.
Reply
#4
(Aug-27-2017, 04:29 PM)DAS Wrote: a password of say 3 characters the while loop does not work as it goes straight to the error message.
If the error message is anything other than print ("Password needs to be between 6 and 12 characters, Password entered is only", length, "characters long"), you would need to share it.
Reply
#5
And check that the indentation that hbknjr used matches the indentation you are using. If the indentation is off, it could be causing that error.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Variable not defined even though it is CoderMerv 3 95 6 hours ago
Last Post: Larz60+
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 515 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,165 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  [variable] is not defined error arises despite variable being defined TheTypicalDoge 4 2,044 Apr-05-2022, 04:55 AM
Last Post: deanhystad
  Simple Password Checker Dexty 8 4,907 Sep-24-2021, 06:49 PM
Last Post: deanhystad
  Function will not return variable that I think is defined Oldman45 6 3,435 Aug-18-2020, 08:50 PM
Last Post: deanhystad
  How to assign a module to a variable even if it's not defined? mandaxyz 5 3,164 Aug-12-2020, 10:34 PM
Last Post: snippsat
  Variable not defined Heyjoe 4 2,490 Jul-10-2020, 11:27 PM
Last Post: Heyjoe
  python library not defined in user defined function johnEmScott 2 3,773 May-30-2020, 04:14 AM
Last Post: DT2000
  Error: variable can not be defined julio2000 2 3,138 Feb-09-2020, 08:51 PM
Last Post: julio2000

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020