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

Thanitsak Leuangsupornpong
Thanitsak Leuangsupornpong
7,490 Points

Challenge Task 2 of 3 on Making Strong Users

I don't know what to do,Thanks for answer!

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

from flask.ext.bcrypt import set_password(hashed_pw)

4 Answers

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello!

You are missing something in the generate_password_hash() call and that is what this generation comes from.

So where does the generate_password_hash() come from in our function? (it comes from one of the two parameters of the function, between the parenthesis)

You need to put that variable inside the parenthesis at the end of the generate_password_hash call

Does it make sense?

Thanitsak Leuangsupornpong
Thanitsak Leuangsupornpong
7,490 Points

Thanks for answer my question!The last Task for This challenge :)I read the instruction already, but still confuse,could help with this one, Thanks!

Question: 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.

from flask.ext.bcrypt import generate_password_hash

from flask.ext.bcrypt import check_password_hash

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

It show name 'validate_password' is not defined

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hell Thanitsak.

Here is what the code challenge asks:

"Now create a function named set_password that takes a User and a string for their password. Hash the password, set the User.password attribute to the hashed password, and return the User."

Let see the steps we want to go through: 1 define a function: we use the keyword "def", followed by the name of the function ("set_password" in this case) and a set of parenthesis "()". Inside the parenthesis we write what the function takes: (User, password)

2 what goes inside the function?

In this case we want to generate a password has for the variable password that our function takes and set it to be the User's password, so:

User.password = ...

where you need to replace the "..." with the actual generate_password_hash() call.

In the end, we want to return the "whole" User, by simply writing:

return User

Let me know if this helps out.

Vittorio

Thanitsak Leuangsupornpong
Thanitsak Leuangsupornpong
7,490 Points

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

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

I do like this, but still not right please help!Thanks!

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hey!

Let's go through this step by step:

  1. Create the function as we did before:so, def validate_password(User, password):

2 inside the function, we need to return True or False after the password match check. I think you could write this in 1 single line. Any ideas?

Vittorio