Builded new structure.
Now with remote setup and management Server more than one Node can be connected added user auth
This commit is contained in:
1 parent
4c98d14352
commit
aae54167a1
25 files changed
+1942
-52
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import crypto from 'node:crypto';
|
||||
|
||||
const keyLength = 64;
|
||||
|
||||
export function hashPassword(password, salt = crypto.randomBytes(16).toString('hex')) {
|
||||
const hash = crypto.scryptSync(String(password), salt, keyLength).toString('hex');
|
||||
return `scrypt$${salt}$${hash}`;
|
||||
}
|
||||
|
||||
export function verifyPassword(password, storedHash) {
|
||||
const [algorithm, salt, hash] = String(storedHash || '').split('$');
|
||||
if (algorithm !== 'scrypt' || !salt || !hash) return false;
|
||||
const candidate = hashPassword(password, salt).split('$')[2];
|
||||
return crypto.timingSafeEqual(Buffer.from(hash, 'hex'), Buffer.from(candidate, 'hex'));
|
||||
}
|
||||
|
||||
export function randomToken(bytes = 32) {
|
||||
return crypto.randomBytes(bytes).toString('hex');
|
||||
}
|
||||
Reference in new issue
Block a user