Welcome to the Treehouse Community
Looking to learn something new?
Bcrypt Challenge Task 3
Task 3: Finally write a function named validate_password that takes a user and a password. It should return True if the provided password, when hashed, matches the user's password. Otherwise, return False.
Error I am getting: Bummer! Returned False for a correct password or True for an incorrect one
from flask.ext.bcrypt import generate_password_hash, check_password_hash def set_password(User, string1): User.password = generate_password_hash('string1') return User def validate_password(User, string1): if check_password_hash(User.password, 'string1'): return True else: return False
Well after rechecking i noticed that you have 'string1' in you if statement. Didn't see it before. Take the single quotes away and watch the magic Python go :D
You have to pass the variable to the method and not a string.
I ain't that far but I think it would be good if you do:
def validate_password(User, string1): if check_password_hash(User.password, 'string1') == True: return True else: return False
Cos your code check the boolean expression in check_password_hash and I evaluates to the state that statement is in.
Meaning if the pass check passes and if evaluates to true then True will be returned. If it evaluates to false then True is returned again because you didn't write a comparement for that statement.
Woongshik Choi42,387 Points
You can simply write the code below,
def validate_password(User, passwordString): return check_password_hash(User.password, passwordString)
I tried several different things, and ended mostly up with the message:"Bummer! Returned False for a correct password or True for an incorrect one". When I switched from my cryptic "psw" to "password", I got it correct. I'm not sure what was stopping it with the psw, and not password, as I did try to take the "" away, like it was suggested earlier.
David Leacock8,532 Points
check_password_hash(User.password, string1), remove the ' ' around string1.
Postica Constantin4,412 Points
Try this, its works for me, if you focus on 2 task, you get response for 3 task, 'user.password'. good Luck
from flask.ext.bcrypt import check_password_hash from flask.ext.bcrypt import generate_password_hash
def set_password(User, string): User.password = generate_password_hash(string) return User
def validate_password(user, password): if check_password_hash(user.password, password): return True else: return False
i need the solution for challenge 2 anyone