i have created password authentication with bcrypt on flask not with database. so the story is that I want to login the password using a hashed password. but can't even log me in. is there something wrong???
@auth.verify_password def authenticate(username, password):
user = 'alfara'
passwd = 'alfara'
if username and password:
pw_hash = bcrypt.generate_password_hash(passwd).decode('utf-8')
if username == user and password == pw_hash:
return bcrypt.check_password_hash(pw_hash, passwd)
else:
return False
return False
CodePudding user response:
The idea of password hashing is that you do not store the clear text password. Your code fail in this. You could just compare passwd and password directly.
- @Klaus D.
If you want, you can do
passwd = bcrypt.generate_password_hash("alfara")
Then do it like this
if username and password:
verify = bcrypt.check_password_hash(passwd, password)
if verify and username == user:
return "Username and Password Matched"