Skip to content

Instantly share code, notes, and snippets.

@rameshbaskar
Created October 25, 2021 14:01
Show Gist options
  • Save rameshbaskar/bd4764674bf0b96bc76a5a2303bf76ee to your computer and use it in GitHub Desktop.
Save rameshbaskar/bd4764674bf0b96bc76a5a2303bf76ee to your computer and use it in GitHub Desktop.
Python - Password encryption and verification
# ensure to run 'pip install passlib'
from passlib.context import CryptContext
plain_text = 'Password@123'
pwd_context = CryptContext(
schemes=['pbkdf2_sha256'],
default='pbkdf2_sha256',
pbkdf2_sha256__default_rounds=40000
)
# Encrypt the password using the password context
enc_password = pwd_context.hash(plain_text)
# Verify the password without 'unhashing' the encrypted password
print(pwd_context.verify(plain_text, enc_password))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment