Provides secure password hashing and verification using Node.js built-in scrypt, suitable for authentication systems without external dependencies.
// Source: https://github.com/Hansade2005/FreeAIGateway | License: MIT | Copyright 2026 Hans Ade
// Provided via justclaw.it.com; keep this notice with the code.
import crypto from 'crypto';
// Password hashing with Node's built-in scrypt (no external dependency).
// Stored format: `scrypt$<saltHex>$<hashHex>`.
const KEYLEN = 64;
const SALT_BYTES = 16;
export function hashPassword(password: string): string {
const salt = crypto.randomBytes(SALT_BYTES);
const hash = crypto.scryptSync(password, salt, KEYLEN);
return `scrypt$${salt.toString('hex')}$${hash.toString('hex')}`;
}
export function verifyPassword(password: string, stored: string): boolean {
const parts = stored.split('$');
if (parts.length !== 3 || parts[0] !== 'scrypt') return false;
const salt = Buffer.from(parts[1]
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key