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

Terrell Stewart
PLUS
Terrell Stewart
Courses Plus Student 4,228 Points

Receiving True for a value that's False or False for a value that's True

The title is self explanatory, but as I look at the code I gave no idea why, maybe the values are not matching up? Can a more experienced eye help me out on this thank you.

from flask.ext.bcrypt import generate_password_hash,check_password_hash


def set_password(User,password):
  User.password = generate_password_hash('Google')
  return User

def validate_password(User,password):
  if check_password_hash(User.password,'Google'):
    return False
  else:
    return False
utils.py
from flask.ext.bcrypt import generate_password_hash,check_password_hash


def set_password(User,password):
  User.password = generate_password_hash('Google')
  return User

def validate_password(User,password):
  if check_password_hash(User.password,'Google'):
    return False
  else:
    return False

1 Answer

Andrew Winkler
Andrew Winkler
37,739 Points

So check_password_hash() is supposed to return true if the 'User' and 'a_string' matches what's in the hash database, but right now you have things poorly labeled, plus the validate password function is returning False when it should be True. This is an easy fix:

from flask.ext.bcrypt import generate_password_hash,check_password_hash

# relabeled 'password' and 'Google' to more accurate or 'a_string' 
def set_password(User, a_string):
  User.password = generate_password_hash(a_string)
  return User

def validate_password(User, a_string):
  if check_password_hash(User.password,a_string):
    # return False -- incorrect
    return True
  else:
    return False
Terrell Stewart
Terrell Stewart
Courses Plus Student 4,228 Points

I thought I changed that before I posted it sorry about that