Bird
0
0

You want to check if a user-entered password matches the stored bcrypt hash in FastAPI. Which code snippet correctly performs this check?

hard🚀 Application Q8 of 15
FastAPI - Authentication and Security
You want to check if a user-entered password matches the stored bcrypt hash in FastAPI. Which code snippet correctly performs this check?
Apwd_context.compare(user_password, stored_hash)
Bpwd_context.hash(user_password) == stored_hash
Cpwd_context.check(user_password, stored_hash)
Dpwd_context.verify(user_password, stored_hash)
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct method for password verification

    Passlib's CryptContext uses verify() to check password against hash.
  2. Step 2: Eliminate incorrect methods

    Hashing and comparing strings directly is wrong because bcrypt hashes differ each time. Methods check() and compare() do not exist.
  3. Final Answer:

    pwd_context.verify(user_password, stored_hash) -> Option D
  4. Quick Check:

    Verify method checks password correctly [OK]
Quick Trick: Use verify() to check password against hash [OK]
Common Mistakes:
MISTAKES
  • Comparing hashes directly
  • Using non-existent methods like check or compare

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes