Reputation: 25
I'm trying to write a program that allows me to get a username and password from a file. I feel like I am on the right track but, when I run the program to test whether or not it works, I get a:
Name error: global name Username is not defined.
Any ideas where I've gone wrong? I apologize if the formatting is off.
def login():
UserName = input("Please enter your user name: ")
passw = input("Please enter your password: ")
check(UserName, passw)
return UserName, passw
def check(user, password):
pword = {}
for line in open('unames_passwords.txt','r'):
user, password = line.split()
pword[user] = password
if user == UserName and password == passw:
return True
print("Thank you for logging in.")
else:
print("Username or password is incorrect")
def main():
login()
main()
Upvotes: 1
Views: 809
Reputation: 887405
Your check
function doesn't have any variable named UserName
.
Instead, it has a parameter named user
, which is then overridden by the line from the file.
You need to change the parameter to a unique name, then use that name.
Upvotes: 3