Last active
September 14, 2020 10:00
-
-
Save lesstif/2d83f1592812f6b8da2eec57dce32ae1 to your computer and use it in GitHub Desktop.
argon2 password hasing algorithm
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
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