Challenge - 5 Problems
Werkzeug Password Hashing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of password hash check
What will be the output of this Flask code snippet using Werkzeug's password hashing?
Flask
from werkzeug.security import generate_password_hash, check_password_hash hashed = generate_password_hash('mypassword') result = check_password_hash(hashed, 'mypassword') print(result)
Attempts:
2 left
💡 Hint
Check if the password matches the hash using check_password_hash.
✗ Incorrect
The generate_password_hash creates a hashed password string. The check_password_hash returns True if the password matches the hash.
❓ Predict Output
intermediate2:00remaining
Result of checking wrong password
What will be the output of this code when checking a wrong password?
Flask
from werkzeug.security import generate_password_hash, check_password_hash hashed = generate_password_hash('secret123') result = check_password_hash(hashed, 'wrongpass') print(result)
Attempts:
2 left
💡 Hint
Check_password_hash returns False if password does not match.
✗ Incorrect
The password 'wrongpass' does not match the hashed 'secret123', so check_password_hash returns False.
📝 Syntax
advanced2:00remaining
Identify the syntax error in password hashing code
Which option contains a syntax error when using Werkzeug's password hashing functions?
Flask
from werkzeug.security import generate_password_hash hashed = generate_password_hash('pass123')
Attempts:
2 left
💡 Hint
Check if method argument is passed as a string or variable.
✗ Incorrect
The method parameter must be a string like 'sha256'. Passing sha256 without quotes causes a NameError or syntax error.
❓ component_behavior
advanced2:00remaining
Behavior of password hash with different salt lengths
What is the effect of changing the salt_length parameter in generate_password_hash?
Flask
from werkzeug.security import generate_password_hash hash1 = generate_password_hash('mypassword', salt_length=8) hash2 = generate_password_hash('mypassword', salt_length=16) print(hash1 == hash2)
Attempts:
2 left
💡 Hint
Salt length affects the randomness added to the hash.
✗ Incorrect
Changing salt_length changes the salt used, so hashes differ even for the same password.
🔧 Debug
expert3:00remaining
Debugging password hash verification failure
A developer uses this code but password verification always fails. What is the cause?
Flask
from werkzeug.security import generate_password_hash, check_password_hash password = 'admin123' hash_pw = generate_password_hash(password) # Later in code result = check_password_hash(password, hash_pw) print(result)
Attempts:
2 left
💡 Hint
Check the order of arguments in check_password_hash.
✗ Incorrect
The check_password_hash function expects the hashed password first, then the plain password. Reversing them causes verification to fail.