mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-11-14 22:07:17 +00:00
Refactor PasswordHasher
This commit is contained in:
parent
4a08687ac8
commit
9faafa7f49
@ -3,17 +3,22 @@ from hashlib import scrypt
|
|||||||
|
|
||||||
|
|
||||||
class PasswordHasher:
|
class PasswordHasher:
|
||||||
@staticmethod
|
n = 16384
|
||||||
def hash(password):
|
r = 8
|
||||||
salt = urandom(32)
|
p = 1
|
||||||
return PasswordHasher.scrypt(password, salt).hex()+salt.hex()
|
dklen = 32
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def verify(password, salted_hash):
|
def hash(cls, password):
|
||||||
|
salt = urandom(32)
|
||||||
|
return cls.scrypt(password, salt).hex() + salt.hex()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def verify(cls, password, salted_hash):
|
||||||
salt = bytes.fromhex(salted_hash)[32:]
|
salt = bytes.fromhex(salted_hash)[32:]
|
||||||
hashdigest = bytes.fromhex(salted_hash)[:32]
|
hashdigest = bytes.fromhex(salted_hash)[:32]
|
||||||
return PasswordHasher.scrypt(password, salt) == hashdigest
|
return cls.scrypt(password, salt) == hashdigest
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def scrypt(password, salt):
|
def scrypt(cls, password, salt):
|
||||||
return scrypt(password.encode(), salt=salt, n=16384, r=8, p=1, dklen=32)
|
return scrypt(password.encode(), salt=salt, n=cls.n, r=cls.r, p=cls.p, dklen=cls.dklen)
|
||||||
|
Loading…
Reference in New Issue
Block a user