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

I passed the first 2 task of the challenge. I was struggling with the second task and now the 3rd one is not passing.

need some help

password_hashing.py
from flask.ext.bcrypt import generate_password_hash 
from flask.ext.bcrypt import check_password_hash #from flask.ext.bcrypt import set_password 
#from flask.ext.bcrypt import validate_password

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

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

1 Answer

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Hi! In your validate function, what you have right now will always return False.

check_password_hash(user.password, password) already returns either True or False because it is checking the user's password against the input password to make sure they match.

if user.password == check_password_hash(user.password, password): Next, you are checking the password (which is a string) against the result of the function (which is a boolean). This will always result to False.

Since check_password_hash(user.password, password) already returns either True or False, you can just return that value.

def validate_password(user.password, password):
  return check_password_hash(user.password, password)

Hey Megan, thank you for reaching out. so I tried the code and its giving me this error, "SyntaxError: invalid syntax".

Megan Amendola
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Oops, I see what it is. I copied your code and you have the function taking user.password when it should only be getting user

def validate_password(user, password):
    return check_password_hash(user.password, password)

I missed it the first pass :) Now that should work

Thank you Megan. I really appreciate you breaking this down for me, this definitely helped with understanding password_hashing.