File size: 342 Bytes
e5b256c
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import hashlib
import secrets


def generate_api_key() -> tuple[str, str]:
    plaintext = secrets.token_urlsafe(32)
    hashed = hashlib.sha256(plaintext.encode()).hexdigest()

    return plaintext, hashed


def verify_api_key(plaintext: str, hashed_key: str) -> bool:
    return hashlib.sha256(plaintext.encode()).hexdigest() == hashed_key