Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using check_password_hash instead of generate_password_hash
Trying to encrypt password directly without hashing
✗ Incorrect
Use generate_password_hash to create a secure hash of the password.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the plain password instead of the hashed password
Confusing argument order
✗ Incorrect
The first argument to check_password_hash must be the stored hashed password.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using insecure hash methods like md5 or sha256
Using 'plain' which does not hash
✗ Incorrect
Use 'bcrypt' as the method for strong salted hashing.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names or using undefined names
Hashing the username instead of the password
✗ Incorrect
Use username as key and hash the password value.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of arguments in check_password_hash
Printing the wrong success message
✗ Incorrect
Check the stored hash against the input password and print 'Access granted!' if valid.