Bird
0
0

Which of the following is the correct way to import and create a bcrypt password context using passlib in FastAPI?

easy📝 Syntax Q12 of 15
FastAPI - Authentication and Security
Which of the following is the correct way to import and create a bcrypt password context using passlib in FastAPI?
Afrom passlib.context import CryptContext pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
Bimport bcrypt pwd_context = bcrypt.PasswordContext()
Cfrom fastapi.security import bcrypt pwd_context = bcrypt.Context()
Dimport passlib pwd_context = passlib.bcrypt()
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct import for bcrypt context

    Passlib's CryptContext is imported from passlib.context and configured with schemes=["bcrypt"].
  2. Step 2: Check syntax correctness

    from passlib.context import CryptContext pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") correctly imports and creates pwd_context with bcrypt scheme and deprecated="auto".
  3. Final Answer:

    from passlib.context import CryptContext pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") -> Option A
  4. Quick Check:

    Correct import and setup = from passlib.context import CryptContext pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") [OK]
Quick Trick: Use CryptContext from passlib.context with schemes=['bcrypt'] [OK]
Common Mistakes:
MISTAKES
  • Importing bcrypt directly instead of CryptContext
  • Using wrong module names like fastapi.security
  • Calling non-existent constructors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes