Our great sponsors
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
That’s it! Your users can now enable 2FA for their accounts and enjoy the additional security it provides. The code used in this blog is available over on here. I hope you found this blog useful.
To create the secret, we’re using the generateSecret method provided by node-2fa package. You can install the package for your project by running the npm command npm install node-2fa --save.
We also generated recovery codes which can be used in case we’re unable to retrieve tokens from 2FA applications. We assign the user a list of recovery codes and each code can be used only once during the authentication process. The recovery codes are random strings generated using the cryptoRandomString library which can be installed using npm install crypto-random-string --save.
We’ll be using qrcode NPM package for generating a QR Code. It can be installed using npm i --save-dev @types/qrcode for TypeScript projects or npm install qrcode --save.