我想在创建用户时创建密码哈希并将它们存储到我的数据库中。我的数据库密码列存储 64 个字符 ( nvarchar(64)) 的哈希值。我的哈希配置:
const byteAmount: number = Number(process.env.BYTE_AMOUNT) || 16;
const iterations: number = Number(process.env.ITERATIONS) || 100;
const length: number = Number(process.env.LENGTH) || 64;
const algorithm: string = process.env.ALGORITHM || 'sha512';
const conversion: string = process.env.CONVERSION || 'Hex';
散列用户纯文本密码时,我使用此功能
public hashPassword = (password: BinaryLike, passwordSalt: BinaryLike): string => {
const { iterations, length, algorithm }: { iterations: number, length: number, algorithm: string } = passwordConfig;
const passwordHash: string = pbkdf2Sync(password, passwordSalt, iterations, length, algorithm).toString(passwordConfig.conversion);
return passwordHash;
}
不幸的是,哈希函数返回一个 128 个字符的密码哈希。是否可以定义散列长度,还是总是返回 128 个字符长的散列?
智慧大石
相关分类