我正在为一个项目的系统工作,该系统询问用户是否要创建帐户或登录。我在第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)")
答案 0 :(得分:1)
这是一个小错误,正如其他人提到的那样。需要一个if
语句内比较以下列方式字符串:
if login_or_signup == "signup":