Development
This commit is contained in:
parent
8a8e947fcf
commit
450c0081f7
9 changed files with 59 additions and 28 deletions
|
|
@ -100,6 +100,28 @@ def get_credentials_key():
|
|||
return base64.urlsafe_b64encode(raw)
|
||||
|
||||
|
||||
def hash_password(plaintext):
|
||||
import hashlib, os as _os
|
||||
salt = _os.urandom(16)
|
||||
h = hashlib.scrypt(plaintext.encode('utf-8'), salt=salt, n=16384, r=8, p=1, dklen=32)
|
||||
return f'scrypt:16384:8:1:{salt.hex()}:{h.hex()}'
|
||||
|
||||
|
||||
def verify_password(plaintext, stored):
|
||||
import hashlib, hmac
|
||||
try:
|
||||
tag, n, r, p, salt_hex, hash_hex = stored.split(':')
|
||||
if tag != 'scrypt':
|
||||
return False
|
||||
salt = bytes.fromhex(salt_hex)
|
||||
expected = bytes.fromhex(hash_hex)
|
||||
h = hashlib.scrypt(plaintext.encode('utf-8'), salt=salt,
|
||||
n=int(n), r=int(r), p=int(p), dklen=len(expected))
|
||||
return hmac.compare_digest(h, expected)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def get_smtp_config():
|
||||
"""Return SMTP settings from app_config.json, falling back to env vars."""
|
||||
cfg = _load_app_config()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue