本文整理汇总了TypeScript中password-hash.isHashed函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isHashed函数的具体用法?TypeScript isHashed怎么用?TypeScript isHashed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isHashed函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: verify
verify(value1: string, value2: string): boolean {
if (!value1 && !value2) return true; // both values null or undefined
if (!value1 || !value2) return false; // one value null or undefined
// both values are hashed or both values are unhashed
if ((passwordHash.isHashed(value1) && passwordHash.isHashed(value2)) ||
(!passwordHash.isHashed(value1) && !passwordHash.isHashed(value2)))
{
return value1 === value2;
}
// Only value2 is hashed
if (!passwordHash.isHashed(value1) && passwordHash.isHashed(value2))
return passwordHash.verify(value1, value2);
// Only value1 is hashed
return passwordHash.verify(value2, value1);
}
示例2: generate
'use strict';
import {generate, verify, isHashed} from 'password-hash';
let password = 'raw-password';
let hashed: string;
hashed = generate(password);
hashed = generate(password, {algorithm: 'sha256'});
hashed = generate(password, {saltLength: 10});
hashed = generate(password, {iterations: 11});
hashed = generate(password, {algorithm: 'sha512', saltLength: 9, iterations: 11});
let isOk: boolean;
isOk = verify(password, hashed);
isOk = isHashed(password);
示例3: isHashed
isHashed(value: string): boolean {
if (!value) return false;
return passwordHash.isHashed(value);
}