DEV Community

Cover image for Ditch Passwords: Add Facial Recognition to Your Website with FACEIO
Dipak Ahirav
Dipak Ahirav

Posted on • Updated on

Ditch Passwords: Add Facial Recognition to Your Website with FACEIO

Introduction

Let’s face it: passwords are a pain. They’re hard to remember, easy to lose, and often the weakest link in your website’s security. What if you could ditch passwords altogether and offer your users a seamless, secure way to log in? Enter FACEIO, a game-changing facial recognition framework that makes it easy to add facial authentication to your website.

In this step-by-step guide, we’ll walk you through how to integrate FACEIO into your site using the correct tools and best practices. Whether you’re building a new project or looking to upgrade your existing site, FACEIO offers a modern solution that enhances both security and user experience.

FACEIO in Action

What is FACEIO?

FACEIO is like having a high-tech security guard at your website’s door—but instead of checking IDs, it checks faces. It’s a powerful yet simple framework that lets users log in using facial recognition, bypassing the need for traditional passwords or even OTPs. With just a few lines of JavaScript, you can add this cutting-edge technology to your site, making it both more secure and more user-friendly.

Prerequisites

Before we dive in, here’s what you’ll need:

  • A basic understanding of HTML, CSS, and JavaScript.
  • A simple HTML website to integrate FACEIO into.
  • A FACEIO account (sign up at FACEIO's website).

Step 1: Setting Up FACEIO

First, you need to create a FACEIO account and set up your application:

  1. Head over to the FACEIO Console and sign up for an account.
  2. Once logged in, create a new application. This will provide you with a unique Public ID.
  3. Keep this Public ID handy, as you’ll need it to initialize the fio.js library.

Step 2: Adding FACEIO to Your Website

Now that you have your FACEIO account and Public ID, let’s integrate FACEIO into your website. We’ll start with a basic HTML file.

Here’s a corrected example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>FACEIO Integration Example</title>
</head>
<body>
    <h1>Login with FACEIO</h1>
    <button id="faceio-button">Authenticate with Face</button>

    <!-- Include the FACEIO JavaScript Library -->
    <script src="https://cdn.faceio.net/fio.js"></script>
    <script>
        // Initialize FACEIO with your Public ID
        const faceio = new faceIO("your-public-id-here");

        // Handle the button click event to initiate facial authentication
        document.getElementById("faceio-button").addEventListener("click", async () => {
            try {
                // Perform authentication using FACEIO
                const response = await faceio.authenticate();

                // If successful, greet the user
                alert(`Hello, ${response.payload.userName}!`);
            } catch (err) {
                // Handle authentication errors
                console.error(err);
                alert("Authentication failed, please try again.");
            }
        });
    </script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Step 3: Breaking Down the Code

Let’s take a closer look at what’s happening in the code:

1.Including the Correct Library:
We use the fio.js library, not SDK.js, by including the correct script tag in our HTML:

   <script src="https://cdn.faceio.net/fio.js"></script>
Enter fullscreen mode Exit fullscreen mode

2.Initializing FACEIO:
Initialize FACEIO using the Public ID obtained from the FACEIO console:

   const faceio = new faceIO("your-public-id-here");
Enter fullscreen mode Exit fullscreen mode

Replace "your-public-id-here" with your actual Public ID.

3.Handling Authentication:
When the user clicks the "Authenticate with Face" button, the following code runs:

   document.getElementById("faceio-button").addEventListener("click", async () => {
       try {
           // Perform authentication using FACEIO
           const response = await faceio.authenticate();

           // If successful, greet the user
           alert(`Hello, ${response.payload.userName}!`);
       } catch (err) {
           // Handle authentication errors
           console.error(err);
           alert("Authentication failed, please try again.");
       }
   });
Enter fullscreen mode Exit fullscreen mode
  • Event Listener: This triggers the authentication process when the button is clicked.
  • Authentication: The faceio.authenticate() function performs facial recognition and returns user data if successful.

Step 4: Enhancing the Article with Useful Links

To ensure developers have all the resources they need, here are some useful links:

These resources will guide you through advanced integrations and offer support from the FACEIO community.

Step 5: Testing It Out

Let’s see it in action! Here’s how you can test your integration:

  1. Save your HTML file and open it in your favorite web browser.
  2. Click the "Authenticate with Face" button.
  3. Follow the on-screen prompts to complete the facial recognition process.

If all goes well, you should see a greeting message with your username after successful authentication.

Conclusion

And there you have it! In just a few simple steps, you’ve added cutting-edge facial recognition to your website using the correct tools and best practices. FACEIO makes it easy to move beyond passwords and offer your users a more secure and modern login experience.

We hope you enjoyed this tutorial. Stay tuned for more guides on how to integrate FACEIO with popular JavaScript frameworks like React, Vue.js, and Angular. In the meantime, feel free to share your thoughts and questions in the comments below!

Additional Resources

Top comments (2)

Collapse
 
neurabot profile image
Neurabot • Edited

Idea that people won't use again password anymore is pretty out of box.

Collapse
 
gadekar_sachin profile image
Sachin Gadekar

it's impressive ...