cl-node-two-factor-authentication
Version:
Two factor authentication
30 lines (24 loc) • 659 B
JavaScript
import speakeasy from "speakeasy";
export class clNodeTwoFactorAuthentication {
generateToken ( length ) {
void 0 === length && ( length = 40 );
return speakeasy.generateSecret({ length });
}
generateTimeBasedToken ( base32, timeInMilliseconds ) {
void 0 === base32 && ( base32 = this.generateCode().base32 );
void 0 === timeInMilliseconds && ( timeInMilliseconds = 60E3 * 6; /* SIX MINUTE */ );
return speakeasy.totp( {
secret: base32,
encoding: "base32",
window: 6
} );
}
validateTimeBasedToken ( base32, token ) {
return speakeasy.totp.verify( {
secret: base32,
encoding: "base32",
token,
window: 6
} );
}
}