Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRoneshia Allen
5,192 PointsI passed the first 2 task of the challenge. I was struggling with the second task and now the 3rd one is not passing.
need some help
from flask.ext.bcrypt import generate_password_hash
from flask.ext.bcrypt import check_password_hash #from flask.ext.bcrypt import set_password
#from flask.ext.bcrypt import validate_password
def set_password(user, password):
generate_password_hash(password)
user.password = generate_password_hash(password)
return user
def validate_password(user.password, password):
if user.password == check_password_hash(user.password, password):
return True
else:
return False
1 Answer
Megan Amendola
Treehouse TeacherHi! In your validate function, what you have right now will always return False.
check_password_hash(user.password, password)
already returns either True or False because it is checking the user's password against the input password to make sure they match.
if user.password == check_password_hash(user.password, password):
Next, you are checking the password (which is a string) against the result of the function (which is a boolean). This will always result to False.
Since check_password_hash(user.password, password)
already returns either True or False, you can just return that value.
def validate_password(user.password, password):
return check_password_hash(user.password, password)
Roneshia Allen
5,192 PointsRoneshia Allen
5,192 PointsHey Megan, thank you for reaching out. so I tried the code and its giving me this error, "SyntaxError: invalid syntax".
Megan Amendola
Treehouse TeacherMegan Amendola
Treehouse TeacherOops, I see what it is. I copied your code and you have the function taking
user.password
when it should only be gettinguser
I missed it the first pass :) Now that should work
Roneshia Allen
5,192 PointsRoneshia Allen
5,192 PointsThank you Megan. I really appreciate you breaking this down for me, this definitely helped with understanding password_hashing.
Megan Amendola
Treehouse TeacherMegan Amendola
Treehouse TeacherGlad I could help!