本文整理汇总了TypeScript中password-hash.generate函数的典型用法代码示例。如果您正苦于以下问题:TypeScript generate函数的具体用法?TypeScript generate怎么用?TypeScript generate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了generate函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getHashedValue
getHashedValue(value: string): string {
if (value && !this.isHashed(value)) {
return passwordHash.generate(value);
}
return value;
}
示例2: it
it('verify() returns false when only one value is null or undefined', () => {
expect(service.verify(null, 'something')).toBeFalsy();
expect(service.verify('something', null)).toBeFalsy();
expect(service.verify(undefined, 'something')).toBeFalsy();
expect(service.verify('something', undefined)).toBeFalsy();
let hashedPassword = passwordHash.generate('myPa$$word');
expect(service.verify(null, hashedPassword)).toBeFalsy();
expect(service.verify(hashedPassword, null)).toBeFalsy();
expect(service.verify(undefined, hashedPassword)).toBeFalsy();
expect(service.verify(hashedPassword, undefined)).toBeFalsy();
})
示例3:
api_router.post('/user', (req, res) => {
console.log("POST /api/user")
let hashed_password = passwordHash.generate(req.body.password)
model.createUser({ name: req.body.name,
email: req.body.email,
password: hashed_password })
.then(user => {
res.json({ user: user});
})
.catch(err => {
res.status(404).json({
title: "Can't create new user",
error: err
});
});
});
示例4: 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);