Created
October 25, 2021 14:01
-
-
Save rameshbaskar/bd4764674bf0b96bc76a5a2303bf76ee to your computer and use it in GitHub Desktop.
Python - Password encryption and verification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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