Home >Web Front-end >JS Tutorial >Passwordless Facial Authentication on Websites! (FACEIO)
FaceIO is a service that allows websites and apps to recognize a person by their face using a webcam.
Instead of typing a password or using a fingerprint, users can just look at the camera, and the app can confirm who they are.
This is helpful because:
There are two main actions with FaceIO:
To use FaceIO, you need to add their JavaScript library (a special code that does the face detection) to your website. Here's how you do it:
1. Include the Script:
Add a script tag in your HTML file that points to FaceIO’s library:
<script src="https://cdn.faceio.net/fio.js"></script>
? This script allows your website to use FaceIO's features.
2. Create Buttons for Enroll and Authenticate:
In your HTML, add two buttons:
<button onclick="enrollNewUser()">Enroll New User</button> <button onclick="authenticateUser()">Authenticate User</button>
? When a user clicks these buttons, they will either enroll (save their face) or authenticate (check their face).
The process of saving a new user’s face is called enrolling. Here’s the JavaScript code for it:
function enrollNewUser() { const faceio = new faceIO("app-public-id"); // Replace with your app's ID faceio.enroll({ locale: "en", // This sets the language to English payload: { email: "user@example.com" // Link this user's email or any other unique ID } }).then(userInfo => { console.log("User enrolled successfully!"); console.log("User ID: " + userInfo.facialId); console.log("Enrollment Date: " + userInfo.timestamp); alert("Enrollment successful! Welcome, user."); }).catch(err => { handleError(err); }); }
?♂️ What Does This Code Do?
This is how you check if a user is who they say they are using their face:
<script src="https://cdn.faceio.net/fio.js"></script>
?♂️ What Does This Code Do?
To get the API key (also known as the **App Public ID) in FaceIO, follow these simple steps:**
Sign Up for FaceIO:
Create a New Application:
Find the App Public ID:
Copy the App Public ID:
Example: Replace "app-public-id" in the JavaScript code with your actual App Public ID:
<button onclick="enrollNewUser()">Enroll New User</button> <button onclick="authenticateUser()">Authenticate User</button>
Now, your app is connected to FaceIO and ready to use facial recognition features!
Before preceding, let me show you how to run FaceIO on a live server.
Running on a Live Server:
First, install node.js in your computer and then instal the following package in FaceIO project:
<script src="https://cdn.faceio.net/fio.js"></script>
Then use it by the following command:
<button onclick="enrollNewUser()">Enroll New User</button> <button onclick="authenticateUser()">Authenticate User</button>
Here is the live server link in your vscode terminal:
Not everything goes smoothly all the time, so we need to handle errors when they occur. Here’s a function that does that:
function enrollNewUser() { const faceio = new faceIO("app-public-id"); // Replace with your app's ID faceio.enroll({ locale: "en", // This sets the language to English payload: { email: "user@example.com" // Link this user's email or any other unique ID } }).then(userInfo => { console.log("User enrolled successfully!"); console.log("User ID: " + userInfo.facialId); console.log("Enrollment Date: " + userInfo.timestamp); alert("Enrollment successful! Welcome, user."); }).catch(err => { handleError(err); }); }
?♂️ What Does This Code Do?
You might wonder why this code needs to run on a server instead of just opening it as a regular file in your browser. Here’s why:
?? JavaScript and Security:
?️ FaceIO Needs to Talk to Its Server:
FaceIO offers a web-based Application Manager. This is like a dashboard where you can control everything about your app:
By following these steps, you can make a website where users can log in just by looking at their webcam! You are turning your website into a futuristic app that recognizes faces and making it more user-friendly and secure to attract your interviewer or client!
I hope this explanation was helpful! It covers everything from how FaceIO works to setting it up and managing it. Let me know if you have any more questions!
Read more: skills to become a backend developer in 6 months (roadmap)
The above is the detailed content of Passwordless Facial Authentication on Websites! (FACEIO). For more information, please follow other related articles on the PHP Chinese website!