Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Build a Social Network with Flask Making Strong Users Cryptographic Hashing with Flask-Bcrypt

Bcrypt Challenge Task 3

Task 3: 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.

Error I am getting: Bummer! Returned False for a correct password or True for an incorrect one

from flask.ext.bcrypt import generate_password_hash, check_password_hash

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

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

Challenge link: https://teamtreehouse.com/library/build-a-social-network-with-flask/making-strong-users/bcryptkeeper

7 Answers

Nejc Vukovic
seal-mask
.a{fill-rule:evenodd;}techdegree
Nejc Vukovic
Full Stack JavaScript Techdegree Student 36,386 Points

Well after rechecking i noticed that you have 'string1' in you if statement. Didn't see it before. Take the single quotes away and watch the magic Python go :D

You have to pass the variable to the method and not a string.

Nejc Vukovic
seal-mask
.a{fill-rule:evenodd;}techdegree
Nejc Vukovic
Full Stack JavaScript Techdegree Student 36,386 Points

Hi,

I ain't that far but I think it would be good if you do:

def validate_password(User, string1):
  if check_password_hash(User.password, 'string1') == True:
    return True
  else:
    return False

Cos your code check the boolean expression in check_password_hash and I evaluates to the state that statement is in.

Meaning if the pass check passes and if evaluates to true then True will be returned. If it evaluates to false then True is returned again because you didn't write a comparement for that statement.

Regards,

Nejc

Still returns the same error even after using your suggested solution.

Woongshik Choi
Woongshik Choi
42,387 Points

You can simply write the code below,

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

I tried several different things, and ended mostly up with the message:"Bummer! Returned False for a correct password or True for an incorrect one". When I switched from my cryptic "psw" to "password", I got it correct. I'm not sure what was stopping it with the psw, and not password, as I did try to take the "" away, like it was suggested earlier.

David Leacock
David Leacock
8,532 Points

try this

check_password_hash(User.password, string1), remove the ' ' around string1.

Postica Constantin
Postica Constantin
4,412 Points

Try this, its works for me, if you focus on 2 task, you get response for 3 task, 'user.password'. good Luck

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

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

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

i need the solution for challenge 2 anyone