import { randomBytes, createHash } from 'crypto';

export async function hashPassword(password: string): Promise<string> {
  const salt = randomBytes(16).toString('hex');
  const hash = createHash('sha256')
    .update(salt + password)
    .digest('hex');
  return `${salt}:${hash}`;
}

export async function compare(password: string, hashed: string): Promise<boolean> {
  const [salt, hash] = hashed.split(':');
  const computedHash = createHash('sha256')
    .update(salt + password)
    .digest('hex');
  return hash === computedHash;
}
