本文整理汇总了TypeScript中speakeasy.generateSecret函数的典型用法代码示例。如果您正苦于以下问题:TypeScript generateSecret函数的具体用法?TypeScript generateSecret怎么用?TypeScript generateSecret使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了generateSecret函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: compose
public compose() {
if (Vesta.isApiServer) {
const replace: any = {
__DB_PASSWORD__: speakeasy.generateSecret({ length: 16, symbols: false }).ascii,
__SALT__: speakeasy.generateSecret({ length: 8, symbols: false }).ascii.replace(/\$/g, "-"),
__SECRET_KEY__: speakeasy.generateSecret({ length: 64 }).ascii.replace(/\$/g, "-"),
};
findInFileAndReplace(`${this.config.name}/vesta/docker-compose.yml`, replace);
}
}
示例2: async
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
// Get 'password' parameter
const [password, passwordErr] = $.str.get(params.password);
if (passwordErr) return rej('invalid password param');
// Compare password
const same = await bcrypt.compare(password, user.password);
if (!same) {
return rej('incorrect password');
}
// Generate user's secret key
const secret = speakeasy.generateSecret({
length: 32
});
await User.update(user._id, {
$set: {
twoFactorTempSecret: secret.base32
}
});
// Get the data URL of the authenticator URL
QRCode.toDataURL(speakeasy.otpauthURL({
secret: secret.base32,
encoding: 'base32',
label: user.username,
issuer: config.host
}), (err, data_url) => {
res({
qr: data_url,
secret: secret.base32,
label: user.username,
issuer: config.host
});
});
});
示例3:
// normal use.
speakeasy.totp({key: 'secret'});
// use a custom time step.
speakeasy.totp({key: 'secret', step: 60});
// use a custom time.
speakeasy.totp({key: 'secret', time: 159183717});
// use a initial time.
speakeasy.totp({key: 'secret', initial_time: 4182881485});
speakeasy.generateSecret({
length: 3,
name: 'testName',
qr_codes: true,
google_auth_qr: true,
otpauth_url: true,
symbols: true
});
speakeasy.generateSecretASCII(5, true);
speakeasy.otpauthURL({
secret: 'otpauthURLSecret',
label: 'otpauthURLLength'
});
speakeasy.totp.verify({secret: "secret", token: "123456"})
speakeasy.totp.verifyDelta({secret: "secret", token: "123456"})
示例4:
// normal use.
speakeasy.totp({secret: 'secret'});
// use a custom time step.
speakeasy.totp({secret: 'secret', step: 60});
// use a custom time.
speakeasy.totp({secret: 'secret', time: 159183717});
// use a initial time.
speakeasy.totp({secret: 'secret', initial_time: 4182881485});
const otpauth_url: string = speakeasy.generateSecret({
length: 3,
name: 'testName',
qr_codes: true,
google_auth_qr: true,
otpauth_url: true,
symbols: true
}).otpauth_url;
const otpauth_url2: string | undefined = speakeasy.generateSecret({
length: 3,
name: 'testName',
}).otpauth_url;
speakeasy.generateSecretASCII(5, true);
speakeasy.otpauthURL({
secret: 'otpauthURLSecret',
label: 'otpauthURLLength'
});