import getpass
from passlib.hash import sha256_crypt
def register():
username = str(input('username '))
password = str(getpass.getpass('password ',stream=None))
exec('global '+username)
exec(username+'=user('+"'"+username+"'"+','+"'"+password+"'"+')')
def hashPassword(password):
Passhash = sha256_crypt.hash(password)
return Passhash
def verifyPassword(password,hashpass):
return sha256_crypt.verify(password,hashpass)
class user(object):
users=[]
def __init__(self, username, password):
password = str(password)
if len(password) <= 20:
self.username = username
user.users.append(username)
self.password = hashPassword(password)
else:
print("No more than 20 characters in the password")
def login(username, passsword):
if username in user.users:
if verifyPassword(password,exec(username+'.password'))==True:
print('logged in.')
else:
print('wrong password')
else:
print('unknown user.')
I am trying to make a text based login/register system since I am fairly new to coding. For some reason something with the register()
function doesn't correctly register a user because when I go to login verifypassword()
it says
if verifyPassword(password,exec(username+'.password'))==True:
File "<string>", line 1, in <module>
NameError: name 'test' is not defined
>>>
if someone could tell me what is happening. I think it it something with global variables but I don't know how to fix it