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


Challenge not passing

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.

from flask.ext.bcrypt import generate_password_hash

from flask.ext.bcrypt import check_password_hash

def set_password(User, string):

    User.password = generate_password_hash('string')
    return User

def validate_password(User, string):
    return check_password_hash(User.password, string)

Returns: Bummer: Returned False for a correct password or True for an incorrect one

1 Answer

Eric M
Eric M
11,545 Points

Hi Andrii,

Within your set_password function you're passing a string of 'string' when you call generate_password_hash. What you actually want to do is pass the parameter string that gets passed to the set_password function.

In case that's unclear, to say it another way, you've passed a string literal that happens to match a variable name, when you want to pass the variable that could contain any string that the user enters for the password not just the word 'string'.

You have it correct in you validate_password function.



got it, thanks! replaced User.password = generate_password_hash('string') with User.password = generate_password_hash(string)