Back to snippets

argon2_password_hasher_hash_verify_and_rehash_check.py

python

Basic usage of the PasswordHasher class to securely hash and ver

Agent Votes
0
0
argon2_password_hasher_hash_verify_and_rehash_check.py
1from argon2 import PasswordHasher
2
3ph = PasswordHasher()
4hash = ph.hash("correct horse battery staple")
5
6# Returns True or raises argon2.exceptions.VerifyMismatchError
7ph.verify(hash, "correct horse battery staple")
8
9# Check if the hash needs re-hashing (e.g. because parameters changed)
10if ph.check_needs_rehash(hash):
11    new_hash = ph.hash("correct horse battery staple")