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 trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Thomas McDonnell](https://secure.gravatar.com/avatar/7be376972c679d2716bcc740e5ffea11?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Thomas McDonnell
8,212 PointsHi guys really need a little help here, I've tried every sort of thing that makes sense here but keep getting an error
The error I am getting is that it returns false when it should be true and vice versa. Originally I just had the check_password_hash() function itself as I thought it returning True or False would be sufficient. However, when I got an error I tried hard coding the logic in as in below but still get the same error.
I'm I just missing something incredibly simple here? or its a silly typo starting me in the face ?
Thanks for the help.
Thomas
from flask.ext.bcrypt import generate_password_hash, check_password_hash
def set_password(User, str_password):
User.password = generate_password_hash('str_password')
return User
def validate_password(User, str_password):
if check_password_hash(User.password, str_password) == True:
return True
else:
return False
1 Answer
![Jennifer Nordell](https://uploads.teamtreehouse.com/production/profile-photos/5432702/micro_jen-square.jpg)
Jennifer Nordell
Treehouse TeacherHi there! You're doing really great, and this might seem odd, but the problem actually lies in your previous step. You are hashing the password with the explicit string ('str_password')
instead of the string that was sent in. Removing the quotes from the argument causes this to pass all three steps so well done!
This is the line you needed:
#note the removal of the single quotes from str_password
User.password = generate_password_hash(str_password)
Now, that being said, if I might make a tiny suggestion? This code for step 3 could be simplified. Because the check_password_hash
is going to return either a True
or a False
we can use that to return the result of the evaluation directly.
You could rewrite the third function as:
def validate_password(User, str_password):
#This line returns True if it was ok and False if it wasn't
return check_password_hash(User.password, str_password)
Hope this helps!
Thomas McDonnell
8,212 PointsThomas McDonnell
8,212 PointsThanks so much, yes originally I had the simplified version however, when I got the error I had assumed I just needed to be more explicit. Wow just a silly semantic error that makes so much sense but I would have never got that with out your help.
Thank you Jennifer