本文整理匯總了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'
});