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

Python Build a Social Network with Flask Making Strong Users Bcryptkeeper

Thomas McDonnell
Thomas McDonnell
8,212 Points

Hi 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

utils.py
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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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! :smiley:

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! :sparkles:

Thomas McDonnell
Thomas McDonnell
8,212 Points

Thanks 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