Last active
April 19, 2018 02:23
-
-
Save miguelmota/faaa7eb82db929187bb56e0de8322f40 to your computer and use it in GitHub Desktop.
Node.js MFA/2FA OTP verify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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