Checkpoint, fixing reset token handling broken in earlier edits.
This commit is contained in:
@@ -2,6 +2,8 @@ import base64
|
||||
import hashlib
|
||||
import secrets
|
||||
|
||||
from .passphrase import is_well_formed
|
||||
|
||||
|
||||
def create_token() -> str:
|
||||
return secrets.token_urlsafe(12) # 16 characters Base64
|
||||
@@ -14,4 +16,10 @@ def session_key(token: str) -> bytes:
|
||||
|
||||
|
||||
def reset_key(passphrase: str) -> bytes:
|
||||
if not is_well_formed(passphrase):
|
||||
raise ValueError(
|
||||
"Trying to reset with a session token in place of a passphrase"
|
||||
if len(passphrase) == 16
|
||||
else "Invalid passphrase format"
|
||||
)
|
||||
return b"rset" + hashlib.sha512(passphrase.encode()).digest()[:12]
|
||||
|
||||
Reference in New Issue
Block a user