gitscope
← marzneshin / v0.5.4 / app/utils/keygen.py
https://dev.kronoz.win/r/marzneshin.git
app/utils/keygen.py · Python
Blame Raw
 1import xxhash
 2import uuid
 3from app.config.env import AuthAlgorithm, AUTH_GENERATION_ALGORITHM
 4
 5
 6def gen_uuid(key: str) -> str:
 7    if AUTH_GENERATION_ALGORITHM == AuthAlgorithm.PLAIN:
 8        return str(uuid.UUID(key))
 9    else:
10        return str(uuid.UUID(bytes=xxhash.xxh128(key.encode()).digest()))
11
12
13def gen_password(key: str) -> str:
14    if AUTH_GENERATION_ALGORITHM == AuthAlgorithm.PLAIN:
15        return key
16    else:
17        return xxhash.xxh128(key.encode()).hexdigest()