Update
This commit is contained in:
+13
-10
@@ -2,6 +2,7 @@ import json
|
||||
import os
|
||||
import hashlib
|
||||
import secrets
|
||||
import bcrypt
|
||||
from copy import deepcopy
|
||||
from typing import Any
|
||||
from app.utils.platform_utils import get_config_dir
|
||||
@@ -28,7 +29,7 @@ _DEFAULT: dict[str, Any] = {
|
||||
"admin_salt": "",
|
||||
"mfa_enabled": False,
|
||||
"mfa_secret": "",
|
||||
"active_profile": "Défaut",
|
||||
"active_profile": "H3",
|
||||
"profiles": {},
|
||||
"wg": deepcopy(_WG_DEFAULT),
|
||||
"ui": {
|
||||
@@ -94,19 +95,21 @@ class Config:
|
||||
self._data["admin_salt"] = ""
|
||||
self._data["admin_password_hash"] = ""
|
||||
else:
|
||||
salt = secrets.token_hex(16)
|
||||
hashed = hashlib.sha256((salt + password).encode()).hexdigest()
|
||||
self._data["admin_salt"] = salt
|
||||
self._data["admin_password_hash"] = hashed
|
||||
hashed = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt(rounds=12))
|
||||
self._data["admin_salt"] = ""
|
||||
self._data["admin_password_hash"] = hashed.decode("utf-8")
|
||||
self.save()
|
||||
|
||||
def check_admin_password(self, password: str) -> bool:
|
||||
salt = self._data.get("admin_salt", "")
|
||||
stored = self._data.get("admin_password_hash", "")
|
||||
if not stored:
|
||||
return True
|
||||
candidate = hashlib.sha256((salt + password).encode()).hexdigest()
|
||||
return secrets.compare_digest(candidate, stored)
|
||||
# Migration transparente : anciens hashes SHA-256 (64 hex chars, pas de $2b$)
|
||||
if not stored.startswith("$2"):
|
||||
salt = self._data.get("admin_salt", "")
|
||||
candidate = hashlib.sha256((salt + password).encode()).hexdigest()
|
||||
return secrets.compare_digest(candidate, stored)
|
||||
return bcrypt.checkpw(password.encode("utf-8"), stored.encode("utf-8"))
|
||||
|
||||
def has_admin_password(self) -> bool:
|
||||
return bool(self._data.get("admin_password_hash", ""))
|
||||
@@ -144,7 +147,7 @@ class Config:
|
||||
|
||||
@property
|
||||
def active_profile(self) -> str:
|
||||
return self._data.get("active_profile", "Défaut")
|
||||
return self._data.get("active_profile", "H3")
|
||||
|
||||
def list_profiles(self) -> list[str]:
|
||||
return list(self._data.get("profiles", {}).keys())
|
||||
@@ -171,7 +174,7 @@ class Config:
|
||||
return False
|
||||
del profiles[name]
|
||||
if self._data.get("active_profile") == name:
|
||||
self._data["active_profile"] = "Défaut"
|
||||
self._data["active_profile"] = "H3"
|
||||
self.save()
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user