Better Programming

Advice for programmers.

Follow publication

Member-only story

How To Implement Two-Factor Authentication Using Node.js and Vue 3

Patrick Kalkman
Better Programming
Published in
9 min readJan 19, 2022

Photo by Morgan Housel on Unsplash

Last week, our product owner asked what it would take to add two-factor authentication to our system. We use Azure Active Directory, which means configuring an extra policy via the Azure portal. This was all we needed to do to enable two-factor authentication.

Triggered by the question of the product owner, I thought it was also time to add two-factor authentication to my side project. I wanted to use a common way of adding two-factor authentication, a Time-based One-Time Password.

This article describes how I used Node.js and Vue.js to implement two-factor authentication in my side project.

You can find the complete source code of the back-end and the front-end in this GitHub repository.

Two-factor Authentication

Two-factor or multi-factor authentication (MFA) is becoming a de facto standard for IT systems. You likely already use several MFA accounts, for example, from Google, GitHub, or Apple. If not, you should enable it!

Multi-factor authentication is a process where a user has to provide many forms of identification during a sign-in event. This could be a cell phone code or a fingerprint scan.

By asking a user for extra identification, you increase the security of your system. It becomes more difficult for an attacker to get or duplicate this other identification.

The difference between two-factor and multi-factor is that two-factor always uses two forms of identification. Multi-factor authentication could involve two or three. In this article, we will implement two-factor authentication.

Time-based One-Time Password (TOTP)

Time-based One-Time Password (TOTP) is a common way of two-factor authentication. It uses an algorithm that generates a token based on the current time. A recent study showed that TOTP is one of the most user-friendly two-factor authentication techniques. The image below shows the process of TOTP.

Patrick Kalkman
Patrick Kalkman

Written by Patrick Kalkman

IT Architect, Developer & Writer focused on open-source, AI, LLMs & AI agents. Embracing agile methodologies, lifelong learning, and knowledge sharing.

No responses yet

Write a response