1. Go to this page and download the library: Download sghimire/mobile-biometric library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sghimire / mobile-biometric example snippets
use Sandip\Biometric\Native\Facades\Biometrics;
// Show the native biometric prompt with defaults
Biometrics::prompt()->prompt();
// Fully configured
Biometrics::prompt()
->id('checkout-auth') // correlate this prompt with its Completed event
->title('Confirm Payment')
->subtitle('Use Face ID to approve this purchase')
->cancelText('Not now')
->allowDeviceCredential() // let the user fall back to PIN/pattern/password
->prompt();
use Sandip\Biometric\Native\Facades\Biometrics;
Biometrics::unlock(); // mark the app as unlocked
Biometrics::lock(); // mark the app as locked again
Biometrics::isUnlocked(); // bool
use Sandip\Biometric\Native\Events\Biometric\Completed;
use Illuminate\Support\Facades\Event;
Event::listen(function (Completed $event) {
$event->success; // bool
$event->id; // ?string — matches the id you passed to ->id(), if any
$event->message; // ?string — error message when success is false (null on user cancel)
if ($event->success) {
\Sandip\Biometric\Native\Facades\Biometrics::unlock();
}
});
use Livewire\Component;
use Sandip\Biometric\Native\Attributes\OnNative;
use Sandip\Biometric\Native\Events\Biometric\Completed;
use Sandip\Biometric\Native\Facades\Biometrics;
class UnlockGate extends Component
{
public function requestUnlock(): void
{
Biometrics::prompt()->title('Unlock App')->prompt();
}
#[OnNative(Completed::class)]
public function onBiometricCompleted(bool $success, ?string $id, ?string $message): void
{
if ($success) {
Biometrics::unlock();
$this->redirect(route('dashboard'));
}
}
}
use Illuminate\Support\Facades\Route;
Route::middleware('biometric.verified')->group(function () {
Route::get('/wallet', WalletController::class);
});
// Optional: redirect to a named route instead of '/' when locked
Route::middleware('biometric.verified:login')->group(function () {
Route::get('/settings/security', SecuritySettingsController::class);
});
// routes/web.php
use Illuminate\Support\Facades\Route;
Route::middleware('biometric.verified:login')->group(function () {
Route::get('/wallet', WalletController::class);
});
use Sandip\Biometric\Native\Facades\Biometrics;
Biometrics::lock();
// app/Livewire/UnlockGate.php
namespace App\Livewire;
use Livewire\Component;
use Sandip\Biometric\Native\Attributes\OnNative;
use Sandip\Biometric\Native\Events\Biometric\Completed;
use Sandip\Biometric\Native\Facades\Biometrics;
class UnlockGate extends Component
{
public bool $failed = false;
public function requestUnlock(): void
{
$this->failed = false;
Biometrics::prompt()
->title('Unlock Wallet')
->subtitle("Confirm it's you to continue")
->allowDeviceCredential()
->prompt();
}
#[OnNative(Completed::class)]
public function onBiometricCompleted(bool $success): void
{
if ($success) {
Biometrics::unlock();
$this->redirect(route('wallet'));
return;
}
$this->failed = true;
}
public function render()
{
return view('livewire.unlock-gate');
}
}