完善客户端模块与工作区能力
This commit is contained in:
29
electron/main/admin-access.ts
Normal file
29
electron/main/admin-access.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { timingSafeEqual } from 'node:crypto';
|
||||
|
||||
const ADMIN_PASSWORD = 'zhiniankeji666';
|
||||
|
||||
let adminSessionUnlocked = false;
|
||||
|
||||
function matchesAdminPassword(password: unknown): boolean {
|
||||
if (typeof password !== 'string') return false;
|
||||
|
||||
const received = Buffer.from(password, 'utf8');
|
||||
const expected = Buffer.from(ADMIN_PASSWORD, 'utf8');
|
||||
return received.length === expected.length && timingSafeEqual(received, expected);
|
||||
}
|
||||
|
||||
export function verifyAdminPassword(password: unknown): boolean {
|
||||
const valid = matchesAdminPassword(password);
|
||||
if (valid) {
|
||||
adminSessionUnlocked = true;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
export function isAdminSessionUnlocked(): boolean {
|
||||
return adminSessionUnlocked;
|
||||
}
|
||||
|
||||
export function lockAdminSession(): void {
|
||||
adminSessionUnlocked = false;
|
||||
}
|
||||
Reference in New Issue
Block a user