0
0
Flaskframework~10 mins

Password storage best practices 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 hash a password using Werkzeug in Flask.

Flask
from werkzeug.security import [1]

hashed_password = [1]('mysecretpassword')
Drag options to blanks, or click blank then click option'
Agenerate_password_hash
Bcheck_password_hash
Chash_password
Dencrypt_password
Attempts:
3 left
💡 Hint
Common Mistakes
Using check_password_hash instead of generate_password_hash
Trying to encrypt password directly without hashing
2fill in blank
medium

Complete the code to verify a password against its hash.

Flask
from werkzeug.security import check_password_hash

is_valid = check_password_hash([1], 'user_input_password')
Drag options to blanks, or click blank then click option'
Apassword_hash
Buser_password
Cplain_password
Dhashed_password
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the plain password instead of the hashed password
Confusing argument order
3fill in blank
hard

Fix the error in the code to properly hash a password with salt.

Flask
hashed = generate_password_hash('mypassword', method=[1])
Drag options to blanks, or click blank then click option'
A'sha256'
B'plain'
C'bcrypt'
D'md5'
Attempts:
3 left
💡 Hint
Common Mistakes
Using insecure hash methods like md5 or sha256
Using 'plain' which does not hash
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that stores usernames with their hashed passwords.

Flask
user_hashes = { [1]: generate_password_hash([2]) for [1], [2] in users.items() }
Drag options to blanks, or click blank then click option'
Ausername
Bpassword
Cuser
Dpwd
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names or using undefined names
Hashing the username instead of the password
5fill in blank
hard

Fill all three blanks to check a password and print a message accordingly.

Flask
if check_password_hash([1], [2]):
    print([3])
else:
    print('Invalid password')
Drag options to blanks, or click blank then click option'
Astored_hash
Binput_password
C'Access granted!'
D'Welcome!'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of arguments in check_password_hash
Printing the wrong success message