Skip to content

Instantly share code, notes, and snippets.

@ties
Last active October 10, 2019 15:24
Show Gist options
  • Save ties/df34aa2dc86d84a00b0acb7f9480cc95 to your computer and use it in GitHub Desktop.
Save ties/df34aa2dc86d84a00b0acb7f9480cc95 to your computer and use it in GitHub Desktop.
from passlib.context import CryptContext
myctx = CryptContext(schemes=['argon2', 'bcrypt'], deprecated=['bcrypt'])
# h ~= hash('password', 'bcrypt')
h="$2b$12$/kdxAcUQ432BgwKzhTwGM.CKq7gDHAhgDIYE3zyTirDahma6EshhK"
myctx.needs_update(h)
# True
(verifies, new_hash) = myctx.verify_and_update("password", h)
# (True,
# '$argon2i$v=19$m=102400,t=2,p=8$oNQ6J0SI8b6XMua8N0YoBQ$QKwJNiEnApvaobhZYiYTdQ')
(verifies, new_hash) = myctx.verify_and_update("wrong_password", h)
# (False, None)
myctx.to_string()
"""
[passlib]
schemes = argon2, bcrypt
deprecated = bcrypt
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment