2 step verification function library with Google Authenticator
npm install js-google-authenticatorjs
/*
* Since the verifyCode function accepts every code...
* ...entered, it is under maintenance.
* @
* Other functions are working.
*/
`
$3
`js
const authenticator = require("js-google-authenticator");
const authenticator = new GoogleAuthenticator();
`
$3
`js
// Use the GoogleAuthenticator class methods
const secretKey = "YOUR_SECRET_KEY";
const code = "123456";
`
$3
`js
const secretKey = authenticator.encode(text);
`
$3
`js
const isValid = authenticator.verifyCode(secretKey, code);
console.log(Code valid: ${isValid});
`
$3
`js
// not neccessary actually
const hotpCode = authenticator.generateHOTP(secretKey, 1234567890);
console.log(HOTP code: ${hotpCode});
// for qr code:
const app = authenticator.forApp(string, secretKey);
console.log(Google Authenticator App Otp Link: ${app});
``