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

Not sure why could is wrong

I've been having problems with this code challenge i've already checked the forums and used others code that people has confirmed as working but will not work for me, Any help much appreciated. Thanks.

from flask.ext.bcrypt import generate_password_hash from flask.ext.bcrypt import 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') == True: return True else: return False

Just to add the code was put like that when i wrote this, hopefully you can understand.

Hey Rona Keogh,

Could you please provide a link to the code challenge you're having an issue with?

Also about the code layout, if you put 3 of these: `

before the start of the code and at the end of the code (The code should be on a new line) then it should pretty-print it :)

Thanks!

1 Answer

Hey Rona,

It looks like the issues are here:

User.password = generate_password_hash('string1')
                                          ^
if check_password_hash(User.password, 'string1')
                                         ^

You are generating and checking the password hash with 'string1', which is a hard-coded String, not a variable. To fix this, get rid of the quotes (') and then the challenge should pass :)

Just a sidenote that won't affect the challenge: You don't actually need the == True for the check_password_hash, the if statement will run if check_password_hash returns true, and the else statement if it returns false anyway.


Hope it helps and if you run into any more issues, give me a shout :)

Thanks very much Harry, this has worked!

Woohoo! Rock on :)