Why should passwords never be stored in plain text?
Storing passwords in plain text is dangerous because if the database is hacked, attackers get direct access to user passwords. This can lead to account theft and further security breaches.
Click to reveal answer
beginner
What is hashing in the context of password storage?
Hashing is a one-way process that converts a password into a fixed-length string of characters. It is designed so you cannot reverse it to get the original password, making it safer to store.
Click to reveal answer
intermediate
What role does a salt play in password hashing?
A salt is a random string added to a password before hashing. It ensures that even if two users have the same password, their hashes will be different, protecting against attacks using precomputed tables.
Click to reveal answer
beginner
Which Python library is recommended for secure password hashing in Flask?
The 'werkzeug.security' module is recommended in Flask. It provides functions like generate_password_hash() and check_password_hash() to safely hash and verify passwords.
Click to reveal answer
intermediate
Why is using a slow hashing algorithm important for password storage?
Slow hashing algorithms make it harder for attackers to try many password guesses quickly. This reduces the risk of brute-force attacks and improves security.
Click to reveal answer
Which of the following is the safest way to store passwords in a Flask app?
AHash passwords using SHA-1 without salt
BUse werkzeug.security's generate_password_hash with salt
CStore passwords as plain text in the database
DEncrypt passwords with reversible encryption
✗ Incorrect
Using werkzeug.security's generate_password_hash adds salt and uses a strong hashing algorithm, making it the safest option.
What does adding a salt to a password hash prevent?
ARainbow table attacks
BPassword length issues
CPassword reuse by users
DDatabase connection errors
✗ Incorrect
Salts prevent rainbow table attacks by making each hash unique, even for identical passwords.
Which function in Flask's Werkzeug library checks if a password matches its hash?
Averify_password()
Bvalidate_password()
Ccheck_password_hash()
Dcompare_hash()
✗ Incorrect
check_password_hash() compares a stored hash with a password attempt securely.
Why should password hashing algorithms be slow?
ATo make brute-force attacks slower
BTo save server resources
CTo speed up user login
DTo reduce password length
✗ Incorrect
Slow hashing algorithms increase the time needed for each guess, making brute-force attacks less practical.
What is a common hashing algorithm used by generate_password_hash in Flask?
AMD5
BSHA-256
CBase64
DPBKDF2
✗ Incorrect
generate_password_hash uses PBKDF2 by default, which is a slow and secure hashing algorithm.
Explain the steps you would take to securely store user passwords in a Flask application.
Think about how to protect passwords from attackers if the database is leaked.
You got /5 concepts.
Describe why salting passwords is important and how it improves security.
Consider what happens if two users have the same password.
You got /4 concepts.
Practice
(1/5)
1. Why should you never store plain text passwords directly in your Flask application's database?
easy
A. Because plain text passwords can be easily stolen if the database is compromised.
B. Because plain text passwords take up more space than hashed passwords.
C. Because Flask does not support storing plain text passwords.
D. Because hashed passwords are faster to compare than plain text passwords.
Solution
Step 1: Understand password security risks
Storing plain text passwords means if someone hacks the database, they get all user passwords directly.
Step 2: Importance of hashing
Hashing transforms passwords into unreadable strings, protecting user data even if the database leaks.
Final Answer:
Because plain text passwords can be easily stolen if the database is compromised. -> Option A
Quick Check:
Password safety = Avoid plain text storage [OK]
Hint: Never store passwords as plain text, always hash first [OK]
Common Mistakes:
Thinking hashing is optional
Believing plain text is safe if database is secure
Confusing hashing with encryption
2. Which of the following is the correct way to hash a password using Werkzeug in Flask?
easy
A. hashed = make_password(password)
B. hashed = generate_password_hash(password)
C. hashed = password_hash(password)
D. hashed = hash_password(password)
Solution
Step 1: Recall Werkzeug's hashing function
Werkzeug provides generate_password_hash to hash passwords securely.
Step 2: Identify correct function usage
The correct function call is generate_password_hash(password), other options are invalid or non-existent.
Final Answer:
hashed = generate_password_hash(password) -> Option B
Quick Check:
Use generate_password_hash() to hash passwords [OK]
Hint: Use generate_password_hash() from Werkzeug to hash passwords [OK]
Common Mistakes:
Using non-existent functions like hash_password
Confusing hashing with encryption functions
Trying to hash passwords manually
3. What will the following Flask code output if the password check is correct?
from werkzeug.security import generate_password_hash, check_password_hash
hashed = generate_password_hash('secret123')
result = check_password_hash(hashed, 'secret123')
print(result)
medium
A. False
B. secret123
C. Error
D. True
Solution
Step 1: Understand generate_password_hash output
This function creates a hashed string from 'secret123'.
Step 2: Check password correctness with check_password_hash
It compares the hashed password with the plain text 'secret123' and returns True if they match.
Final Answer:
True -> Option D
Quick Check:
check_password_hash returns True if passwords match [OK]
Hint: check_password_hash returns True when password matches hash [OK]
Common Mistakes:
Expecting the original password as output
Confusing True/False return values
Assuming check_password_hash modifies the hash
4. Identify the error in this Flask password check code:
from werkzeug.security import generate_password_hash, check_password_hash
hashed = generate_password_hash('mypassword')
if check_password_hash('mypassword', hashed):
print('Access granted')
medium
A. The hashed and plain password arguments are reversed in check_password_hash.
B. generate_password_hash should not be used for hashing passwords.
C. The print statement should be outside the if block.
D. There is no error; the code works correctly.
Solution
Step 1: Check argument order in check_password_hash
The first argument must be the hashed password, second is the plain password.
Step 2: Identify the reversed arguments
The code passes plain password first and hash second, causing a logic error.
Final Answer:
The hashed and plain password arguments are reversed in check_password_hash. -> Option A
Quick Check:
check_password_hash(hash, password) order matters [OK]
Hint: Pass hashed first, plain password second to check_password_hash [OK]
Common Mistakes:
Swapping arguments in check_password_hash
Using generate_password_hash incorrectly
Ignoring function argument order
5. You want to securely store user passwords in your Flask app and verify them on login. Which approach follows best practices?
hard
A. Store plain passwords in the database and compare them directly on login.
B. Encrypt passwords with a reversible method and decrypt them on login to compare.
C. Hash passwords with generate_password_hash before storing, then verify with check_password_hash during login.
D. Store passwords as plain text but log them only during login attempts.
Solution
Step 1: Understand secure password storage
Passwords must be hashed before storing to prevent exposure if database leaks.
Step 2: Verify passwords securely on login
Use check_password_hash to compare the stored hash with the login password safely.
Final Answer:
Hash passwords with generate_password_hash before storing, then verify with check_password_hash during login. -> Option C
Quick Check:
Hash before store, verify with check_password_hash [OK]
Hint: Hash before store, verify with check_password_hash on login [OK]
Common Mistakes:
Storing or logging plain passwords
Using reversible encryption instead of hashing
Comparing plain passwords directly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.