update Tue 07/14/2026 11:38:16.92
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/* Simple token auth for final mode. */
|
||||
const crypto = require('crypto');
|
||||
const tokens = new Map(); // token -> expiry
|
||||
const TTL = 12 * 60 * 60 * 1000;
|
||||
|
||||
module.exports = {
|
||||
login(password) {
|
||||
const expected = process.env.ADMIN_PASSWORD;
|
||||
if (!expected || password !== expected) return null;
|
||||
const t = crypto.randomBytes(24).toString('hex');
|
||||
tokens.set(t, Date.now() + TTL);
|
||||
return t;
|
||||
},
|
||||
check(t) {
|
||||
if (!t) return false;
|
||||
const exp = tokens.get(t);
|
||||
if (!exp) return false;
|
||||
if (Date.now() > exp) { tokens.delete(t); return false; }
|
||||
return true;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user