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

validate_password that takes a user and a password. It should return True if the provided password, when hashed, matche

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. ... what is this missing? please help =)

utils.py
from flask.ext.bcrypt import check_password_hash
from flask.ext.bcrypt import generate_password_hash


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


def validate_password(user, password):
  try:
    password == generate_password_hash(password)
  return False

3 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You can't compare hashes that way. That's why we have check_password_hash. Also, your try: needs an except: or a finally:.

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

from flask.ext.bcrypt import check_password_hash
from flask.ext.bcrypt import generate_password_hash


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

def validate_password(user, password):
  try:
    password = generate_password_hash(password)
    password == check_password_hash(password)
  except: True
  return False

how is this getting reversed?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

You're not checking the passed-in password. Read the docs on checking a hashed password or watch the video again.

Austin Honaker
Austin Honaker
9,421 Points

Kenneth,

It's pathetic the way you keep dodging questions... The amount of topics created just on this test alone through a simple Google search is astonishing. This was done through the console but now we have to write it out....Come on man. Help people, walk them through what to do instead of always saying "read the docks or watch the video, again".