Blog Detail

08

Sep
Easily Add Face Authentication to Your Laravel Applications cover image

arrow_back Easily Add Face Authentication to Your Laravel Applications

Laravel Face Auth is an awesome package that utilizes Microsoft’s cognitive API to identify faces instead of passwords for your Laravel application.

Note: Please do not use face recognition as an alternative for password authentication in a production system!

Installation

You can install this amazing package via Composer:

$ composer require mpociot/laravel-face-auth

Add the service provider to your config/app.php:

Mpociot\FaceAuth\FaceAuthServiceProvider::class,

In your config/auth.php, change the auth driver to faceauth:

'providers' => [
    'users' => [
        'driver' => 'faceauth',
        'model' => App\User::class,
    ],
]

Publish the configuration:

$ php artisan vendor:publish --provider="Mpociot\FaceAuth\FaceAuthServiceProvider"

Edit the newly published config/faceauth.php file and enter your Face API key.

Usage and authorization

Face authentication works, by using a reference image of your user and matching it against an uploaded image upon login. So this pretty much is the same flow as comparing two password hashes.

When you register your users, you need to make sure that you store a photo of the users face - this is basically his password.

In order for this package, to find the user photo, your User model needs to implement the FaceAuthenticatable interface.

This interface only has one single public method getFaceAuthPhoto(). This method needs to return the content of the user photo.

Example

class User extends Authenticatable implements FaceAuthenticatable
{

    public function getFaceAuthPhoto()
    {
        return File::get(storage_path('facces') . $this->id . '.png');
    }
    
}

Your login form now needs a photo field (the name can be configured) - this field should contain a base64 representation of the image, the user uses to log in.

If you want a simple way to capture the user image from the webcam, take a look at the vue-webcam Vue.js component.

For more details about this package, Please Visit Github.

Published at : 08-09-2022

Author : Rizwan Aslam
AUTHOR
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project