0
0
Flaskframework~10 mins

User model with password in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the password hashing function.

Flask
from werkzeug.security import [1]
Drag options to blanks, or click blank then click option'
Agenerate_password_hash
Bhash_password
Ccheck_password_hash
Dpassword_hash
Attempts:
3 left
💡 Hint
Common Mistakes
Using check_password_hash instead of generate_password_hash
Trying to import a non-existent function like hash_password
2fill in blank
medium

Complete the code to define the password field in the User model.

Flask
password_hash = db.Column(db.[1](128), nullable=False)
Drag options to blanks, or click blank then click option'
AInteger
BString
CText
DBoolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using Integer or Boolean types for password hash
Using Text which allows unlimited length but is less common here
3fill in blank
hard

Fix the error in the method that sets the password hash.

Flask
def set_password(self, password):
    self.password_hash = [1](password)
Drag options to blanks, or click blank then click option'
Acheck_password_hash
Bhash_password
Cpassword_hash
Dgenerate_password_hash
Attempts:
3 left
💡 Hint
Common Mistakes
Using check_password_hash instead of generate_password_hash
Trying to assign the password string directly
4fill in blank
hard

Fill both blanks to complete the method that verifies a password.

Flask
def check_password(self, password):
    return [1](self.password_hash, [2])
Drag options to blanks, or click blank then click option'
Acheck_password_hash
Bpassword
Cgenerate_password_hash
Dself.password
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of arguments
Using generate_password_hash instead of check_password_hash
5fill in blank
hard

Fill all three blanks to complete the User model with password methods.

Flask
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), unique=True, nullable=False)
    password_hash = db.Column(db.String(128), nullable=False)

    def set_password(self, password):
        self.password_hash = [1](password)

    def check_password(self, password):
        return [2](self.password_hash, [3])
Drag options to blanks, or click blank then click option'
Agenerate_password_hash
Bpassword
Ccheck_password_hash
Dhash_password
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up generate_password_hash and check_password_hash
Passing the wrong argument to check_password_hash