What is the purpose of password hashing in web applications?
Password hashing protects user passwords by converting them into a secure, unreadable format. This way, even if the database is leaked, attackers cannot see the original passwords.
Click to reveal answer
beginner
Which Werkzeug functions are commonly used for password hashing and verification?
Werkzeug provides generate_password_hash() to create a hashed password and check_password_hash() to verify a password against its hash.
Click to reveal answer
beginner
How do you hash a password using Werkzeug in Flask?
Use generate_password_hash(password) where password is the plain text password. It returns a hashed string safe to store in the database.
Click to reveal answer
beginner
How do you check if a user-entered password matches the stored hash?
Use check_password_hash(stored_hash, password). It returns True if the password matches the hash, otherwise False.
Click to reveal answer
beginner
Why should you never store plain text passwords in your database?
Storing plain text passwords risks user security if the database is leaked. Hashing ensures passwords are protected and unreadable by attackers.
Click to reveal answer
Which Werkzeug function creates a hashed password?
Averify_password()
Bcheck_password_hash()
Chash_password()
Dgenerate_password_hash()
✗ Incorrect
generate_password_hash() creates a secure hashed password string.
What does check_password_hash() return if the password matches?
AThe hashed password
BTrue
CFalse
DThe plain password
✗ Incorrect
check_password_hash() returns True if the password matches the stored hash.
Why is hashing passwords important?
ATo protect passwords if the database leaks
BTo speed up login
CTo make passwords longer
DTo store passwords in plain text
✗ Incorrect
Hashing protects passwords from being exposed if the database is compromised.
Which of these is NOT a good practice for password security?
AHashing passwords before storing
BUsing <code>generate_password_hash()</code>
CStoring plain text passwords
DVerifying passwords with <code>check_password_hash()</code>
✗ Incorrect
Storing plain text passwords is insecure and should be avoided.
What type of value does generate_password_hash() return?
AHashed password string
BBoolean
CPlain text password
DInteger
✗ Incorrect
It returns a hashed password string safe for storage.
Explain how to securely store and verify passwords in a Flask app using Werkzeug.
Think about the two main Werkzeug functions and why hashing is important.
You got /4 concepts.
Describe why password hashing is critical for user security and what risks it prevents.
Consider what happens if passwords are stored as plain text.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using generate_password_hash in a Flask app?
easy
A. To generate random passwords for users
B. To check if a password matches the stored hash
C. To encrypt the entire user database
D. To securely convert a plain password into a hashed version before storing
Solution
Step 1: Understand the role of generate_password_hash
This function takes a plain password and creates a hashed version that is safe to store.
Step 2: Differentiate from other functions
check_password_hash is used to verify passwords, not generate them. Encryption of the whole database or generating random passwords are unrelated.
Final Answer:
To securely convert a plain password into a hashed version before storing -> Option D
Quick Check:
Password hashing = secure storage [OK]
Hint: Hash passwords before storing to keep them safe [OK]
Common Mistakes:
Confusing hashing with encryption
Using check_password_hash to create hashes
Thinking hashing generates random passwords
2. Which of the following is the correct way to import the password hashing functions from Werkzeug?
easy
A. from flask import generate_password_hash, check_password_hash
B. import werkzeug.hash as wh
C. from werkzeug.security import generate_password_hash, check_password_hash
D. import werkzeug.security.hash_password
Solution
Step 1: Recall the correct import path
The password hashing functions are in werkzeug.security, so import them directly from there.
Step 2: Check each option
from werkzeug.security import generate_password_hash, check_password_hash correctly imports both functions. import werkzeug.hash as wh uses a wrong module alias. from flask import generate_password_hash, check_password_hash tries to import from Flask, which is incorrect. import werkzeug.security.hash_password uses a non-existent import path.
Final Answer:
from werkzeug.security import generate_password_hash, check_password_hash -> Option C
Quick Check:
Correct import path = from werkzeug.security import generate_password_hash, check_password_hash [OK]
Hint: Import from werkzeug.security for hashing functions [OK]