Bird
0
0

Given the following code snippet, what will be the output of print(pwd_context.verify('secret123', hashed_password)) if hashed_password is generated by hashing 'secret123'?

medium📝 component behavior Q13 of 15
FastAPI - Authentication and Security
Given the following code snippet, what will be the output of print(pwd_context.verify('secret123', hashed_password)) if hashed_password is generated by hashing 'secret123'?
from passlib.context import CryptContext
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
hashed_password = pwd_context.hash('secret123')
print(pwd_context.verify('secret123', hashed_password))
ARaises a TypeError
BTrue
CFalse
DPrints the hashed password string
Step-by-Step Solution
Solution:
  1. Step 1: Understand pwd_context.hash and verify

    pwd_context.hash creates a hashed password from the plain text. verify checks if the plain text matches the hash.
  2. Step 2: Analyze the verify call

    Since 'secret123' was hashed and then verified against the same string, verify returns True.
  3. Final Answer:

    True -> Option B
  4. Quick Check:

    Verify correct password = True [OK]
Quick Trick: Verify returns True if password matches hash [OK]
Common Mistakes:
MISTAKES
  • Expecting verify to return the hash
  • Confusing verify output with hash output
  • Thinking verify raises errors on match

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes