diff --git a/.env.example b/.env.example
@@ -38,3 +38,4 @@ UVICORN_PORT = 8000
# WEBHOOK_SECRET = "something-very-very-secret"
# VITE_BASE_API="https://example.com/api/"
# JWT_ACCESS_TOKEN_EXPIRE_MINUTES = 1440
+# AUTH_GENERATION_ALGORITHM=xxh128
diff --git a/app/config/env.py b/app/config/env.py
@@ -1,5 +1,6 @@
from decouple import config
from dotenv import load_dotenv
+from enum import Enum
load_dotenv()
@@ -65,6 +66,18 @@ CLASH_SUBSCRIPTION_TEMPLATE = config(
WEBHOOK_ADDRESS = config("WEBHOOK_ADDRESS", default=None)
WEBHOOK_SECRET = config("WEBHOOK_SECRET", default=None)
+
+class AuthAlgorithm(Enum):
+ PLAIN = "plain"
+ XXH128 = "xxh128"
+
+
+AUTH_GENERATION_ALGORITHM = config(
+ "AUTH_GENERATION_ALGORITHM",
+ cast=AuthAlgorithm,
+ default=AuthAlgorithm.XXH128,
+)
+
# recurrent notifications
# timeout between each retry of sending a notification in seconds
diff --git a/app/utils/keygen.py b/app/utils/keygen.py
@@ -1,10 +1,17 @@
import xxhash
import uuid
+from app.config.env import AuthAlgorithm, AUTH_GENERATION_ALGORITHM
def gen_uuid(key: str) -> str:
- return str(uuid.UUID(bytes=xxhash.xxh128(key.encode()).digest()))
+ if AUTH_GENERATION_ALGORITHM == AuthAlgorithm.PLAIN:
+ return str(uuid.UUID(key))
+ else:
+ return str(uuid.UUID(bytes=xxhash.xxh128(key.encode()).digest()))
def gen_password(key: str) -> str:
- return xxhash.xxh128(key.encode()).hexdigest()
+ if AUTH_GENERATION_ALGORITHM == AuthAlgorithm.PLAIN:
+ return key
+ else:
+ return xxhash.xxh128(key.encode()).hexdigest()