const SALT = '盐值';

export const hashPassword = (password) => {
  if (!password) return '';
  const hash = crypto.createHash('sha256');
  hash.update(password + SALT);
  return hash.digest('hex');
};

export const verifyPassword = (inputPassword, hashedPassword) => {
  if (!inputPassword || !hashedPassword) return false;
  const hashedInput = hashPassword(inputPassword);
  return hashedInput === hashedPassword;
};
最后修改:2026 年 05 月 15 日
如果觉得我的文章对你有用,请随意赞赏