Installation Add the package via Composer:
composer require xlabs/fingerprintbundle
Register the bundle in config/app.php under providers:
Xlabs\FingerprintBundle\FingerprintServiceProvider::class,
Publish the configuration (if needed):
php artisan vendor:publish --provider="Xlabs\FingerprintBundle\FingerprintServiceProvider" --tag="config"
Basic Usage
Inject the FingerprintManager service into a controller or service:
use Xlabs\FingerprintBundle\Services\FingerprintManager;
public function __construct(private FingerprintManager $fingerprintManager) {}
Capture a fingerprint (simplified example):
$fingerprintData = $this->fingerprintManager->capture();
First Use Case: Enrollment
Enroll a user’s fingerprint (assuming a User model):
$user = User::find(1);
$this->fingerprintManager->enroll($user, $fingerprintData);
Capture Trigger the device’s fingerprint scanner (hardware/software) via:
$fingerprintData = $this->fingerprintManager->capture();
Note: May require frontend integration (e.g., JavaScript SDK) for mobile/web apps.
Verification Check against stored templates:
$isMatch = $this->fingerprintManager->verify($user, $fingerprintData);
Fallback Handling Use middleware to redirect to alternative auth (e.g., OTP) if fingerprint fails:
if (!$isMatch) {
return redirect()->route('auth.otp');
}
users table with:
Schema::table('users', function (Blueprint $table) {
$table->string('fingerprint_template')->nullable();
$table->timestamp('fingerprint_enrolled_at')->nullable();
});
public function handle(FingerprintEnrolled $event) {
Log::info("User {$event->user->id} enrolled fingerprint.");
}
$this->fingerprintManager->verify($user, $data, maxAttempts: 3);
Hardware Dependency
webauthn for web) or document supported devices.Data Sensitivity
Fallback Logic
Logs
Enable debug mode in config/fingerprint.php:
'debug' => env('APP_DEBUG', false),
Check logs for FingerprintBundle entries.
Template Validation Verify template storage/format:
$this->fingerprintManager->validateTemplate($user->fingerprint_template);
Custom Storage Override the default template storage (e.g., AWS S3):
$this->fingerprintManager->setStorage(new S3FingerprintStorage());
Multi-Factor Integration Combine with Laravel’s built-in auth:
if ($this->fingerprintManager->verify($user, $data)) {
Auth::login($user, remember: true);
}
Testing
Mock the FingerprintManager in PHPUnit:
$mock = Mockery::mock(FingerprintManager::class);
$mock->shouldReceive('verify')->andReturn(true);
How can I help you explore Laravel packages today?