Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active April 19, 2018 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/faaa7eb82db929187bb56e0de8322f40 to your computer and use it in GitHub Desktop.
Save miguelmota/faaa7eb82db929187bb56e0de8322f40 to your computer and use it in GitHub Desktop.
Node.js MFA/2FA OTP verify
import otplib from 'otplib'
export default function verify (mfaSecret, mfaCode) {
mfaCode = (mfaCode||'').replace(/[^\d]+/gi, '')
return otplib.authenticator.verify({
secret: mfaSecret,
token: mfaCode
})
// const secret = otplib.authenticator.generateSecret() 
// console.log(secret) // secret to import into app
// const code = 123456 // from app
// console.log(verify(secret, code))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment