0
0
Flaskframework~20 mins

Password hashing with Werkzeug in Flask - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Werkzeug Password Hashing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
ASyntaxError
BFalse
CTypeError
DTrue
Attempts:
2 left
💡 Hint
Check if the password matches the hash using check_password_hash.
Predict Output
intermediate
2: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)
AFalse
BTrue
CValueError
DNone
Attempts:
2 left
💡 Hint
Check_password_hash returns False if password does not match.
📝 Syntax
advanced
2: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')
Ahashed = generate_password_hash('pass123', method='sha256')
Bhashed = generate_password_hash('pass123')
Chashed = generate_password_hash('pass123', method=sha256)
Dhashed = generate_password_hash('pass123', salt_length=8)
Attempts:
2 left
💡 Hint
Check if method argument is passed as a string or variable.
component_behavior
advanced
2: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)
AFalse, hashes differ because salt length changes the hash
BTrue, hashes are always the same regardless of salt length
CTypeError, salt_length is not a valid parameter
DValueError, salt_length must be 12
Attempts:
2 left
💡 Hint
Salt length affects the randomness added to the hash.
🔧 Debug
expert
3: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)
Apassword variable is not a string
Bcheck_password_hash arguments are reversed; first should be hash, second password
Ccheck_password_hash requires bytes, not strings
Dgenerate_password_hash returns None, causing failure
Attempts:
2 left
💡 Hint
Check the order of arguments in check_password_hash.