Skip to content

Instantly share code, notes, and snippets.

@lesstif
Last active September 14, 2020 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lesstif/2d83f1592812f6b8da2eec57dce32ae1 to your computer and use it in GitHub Desktop.
Save lesstif/2d83f1592812f6b8da2eec57dce32ae1 to your computer and use it in GitHub Desktop.
argon2 password hasing algorithm
from argon2 import PasswordHasher
from argon2.exceptions import VerifyMismatchError
memory_cost = 1 << 17
time_cost = 4
parallelism = 2
ph = PasswordHasher(time_cost, memory_cost, parallelism)
## 암호
pwd = 'secret1'
hash = ph.hash(pwd)
## argon2 해시 출력:
## Ex: $argon2id$v=19$m=102400,t=2,p=8$5gOwqIw5RgkBdw8HXERMLA$9LGcXSLtnENcOfVt9PTxBg
print(hash)
## 암호 검증
ph.verify(hash, pwd)
try:
ph.verify(hash, 'invalid')
except VerifyMismatchError:
print ("invalid password")
except:
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment