我正在为一个项目开发一个系统,该系统询问用户是否要创建帐户或登录。第 5 行的“if”条件有问题。整个错误消息是:
Traceback (most recent call last):
File "main.py", line 5, in <module>
if login_or_signup("signup"):
TypeError: 'str' object is not callable
编码:
import uuid
import hashlib
login_or_signup = input("would you like to log in? Or signup?: ")
if login_or_signup("signup"):
def hash_password(password):
# uuid is used to generate a random number
salt = uuid.uuid4().hex
return hashlib.sha256(salt.encode() + password.encode()).hexdigest() + ':' + salt
def check_password(hashed_password, user_password):
password, salt = hashed_password.split(':')
return password == hashlib.sha256(salt.encode() + user_password.encode()).hexdigest()
new_pass = input('Please enter a password: ')
hashed_password = hash_password(new_pass)
old_pass = input('Now please enter the password again to check: ')
if check_password(hashed_password, old_pass):
print('The passwords match!')
else:
print('I am sorry but the password does not match')
else:
print("(NOT CODED YET)")
繁花不似锦
相关分类