新增navcat解密工具、优化后台UI

This commit is contained in:
MasonLiu committed 2026-09-12 01:36:59 +08:00
1 parent 7b3d45b153
commit bf772046cc
20 files changed
+4409 -2670

No files matched your search

+13 -5
View File
@@ -42,14 +42,22 @@ function hp_verify_user(string $username, string $plain): bool
return hash_equals($row['password_hash'], hp_password_hash($plain));
}
/** 执行登录(成功返回 true) */
function hp_login(string $username, string $plain): bool
/** 执行登录(成功返回 true;成功/失败均写入登录日志与设备信息) */
function hp_login(string $username, string $plain, string $deviceClient = ''): bool
{
$uaRaw = (string) ($_SERVER['HTTP_USER_AGENT'] ?? '');
if (hp_verify_user($username, $plain)) {
session_regenerate_id(true);
$_SESSION['admin'] = $username;
// 记录本次登录信息(供后台“登录信息”卡片展示)
$_SESSION['login_at'] = date('Y-m-d H:i:s');
$_SESSION['login_ip'] = client_ip();
$_SESSION['login_ua'] = login_ua_brief($uaRaw);
$_SESSION['login_device'] = login_device_brief($deviceClient, $uaRaw);
login_log_write($username, 'ok', $deviceClient);
return true;
}
login_log_write($username, 'fail', $deviceClient);
return false;
}
@@ -59,14 +67,14 @@ function hp_change_password(string $oldPlain, string $newPlain): array
if (!is_logged_in()) {
return [false, '未登录'];
}
if (!hp_verify_user((string)$_SESSION['admin'], $oldPlain)) {
if (!hp_verify_user((string) $_SESSION['admin'], $oldPlain)) {
return [false, '原密码不正确'];
}
if (strlen($newPlain) < 6) {
return [false, '新密码至少 6 位'];
}
$st = db()->prepare('UPDATE users SET password_hash = ? WHERE username = ?');
$st->execute([hp_password_hash($newPlain), (string)$_SESSION['admin']]);
$st->execute([hp_password_hash($newPlain), (string) $_SESSION['admin']]);
return [true, '密码修改成功'];
}
@@ -87,7 +95,7 @@ function csrf_token(): string
if (empty($_SESSION['csrf'])) {
$_SESSION['csrf'] = bin2hex(random_bytes(16));
}
return (string)$_SESSION['csrf'];
return (string) $_SESSION['csrf'];
}
function csrf_field(): string