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 A Social Network with Flask Making Strong Users Bcryptkeeper

Validate Password - What am I doing wrong?

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.

password_hashing.py
from flask.ext.bcrypt import generate_password_hash, check_password_hash

def set_password(user, password):
    user = user
    password = generate_password_hash(password)
    user.password = password
    return user

def validate_password(user, password):
    if user.password == check_password_hash(password):
        return True
    else:
        return False

Output: AssertionError: 'check_password_hash(user.password, password)' not found in 'from flask.ext.bcrypt import generate_password_hash, check_password_hash\n\ndef set_password(user, password):\n user = user\n password = generate_password_hash(password)\n user.password = password\n return user\n\ndef validate_password(user, password):\n if user.password == check_password_hash(password):\n return True\n else:\n return False' : Make sure to check the user's password against the password being passed into the function.

1 Answer

Nevermind, I figured it out.

from flask.ext.bcrypt import generate_password_hash, check_password_hash

def set_password(user, password):
    user = user
    password = generate_password_hash(password)
    user.password = password
    return user

def validate_password(user, password):
    if check_password_hash(user.password, password):
        return True
    else:
        return False