Biometric Authentication Fingerprint Example

Overview

Biometric Authentication Fingerprint Example

See the blog post of this project here


Project Presentation


  1. First, let's add the Biometric library to our project.
    dependencies {
      implementation("androidx.biometric:biometric:1.2.0-alpha03")
    }

  2. After adding our library, let's do the necessary coding for situations such as whether the device has biometric authentication or not.
    val biometricManager = BiometricManager.from(this)
    when (biometricManager.canAuthenticate(BIOMETRIC_STRONG or DEVICE_CREDENTIAL)) {
    BiometricManager.BIOMETRIC_SUCCESS ->
        Toast.makeText(this,"App can authenticate using biometrics.",Toast.LENGTH_SHORT).show()
    BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE ->
        Toast.makeText(this,"No biometric features available on this device.",Toast.LENGTH_SHORT).show()
    BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE ->
        Toast.makeText(this,"Biometric features are currently unavailable.",Toast.LENGTH_SHORT).show()
    BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED ->
        Toast.makeText(this,"The device does not have any biometric credentials",Toast.LENGTH_SHORT).show()
    BiometricManager.BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED ->
        Toast.makeText(this,"A security vulnerability has been discovered and the sensor is unavailable until a security update has addressed this issue.",Toast.LENGTH_SHORT).show()
    BiometricManager.BIOMETRIC_ERROR_UNSUPPORTED ->
        Toast.makeText(this,"A given authenticator combination is not supported by the device.",Toast.LENGTH_SHORT).show()
    BiometricManager.BIOMETRIC_STATUS_UNKNOWN ->
        Toast.makeText(this,"Unable to determine whether the user can authenticate.",Toast.LENGTH_SHORT).show()
    }

  1. Now let's show the user the authentication dialog. First of all, let's create the following variables in the class.

    private lateinit var executor: Executor
    private lateinit var biometricPrompt: BiometricPrompt
    private lateinit var promptInfo: BiometricPrompt.PromptInfo

  2. Then let's define these values in order.

    executor = ContextCompat.getMainExecutor(this)
    biometricPrompt = BiometricPrompt(this, executor,
    object : BiometricPrompt.AuthenticationCallback() {
        override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
            super.onAuthenticationError(errorCode, errString)
            Toast.makteText(this,errString.toString(),Toast.LENGTH_SHORT).show()
        }
    
        override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
            super.onAuthenticationSucceeded(result)
            Toast.makteText(this,"Authentication Success",Toast.LENGTH_SHORT).show()
            startActivity(Intent(this@MainActivity,SecondActivity::class.java))
        }
    
        override fun onAuthenticationFailed() {
            super.onAuthenticationFailed()
            Toast.makteText(this,"Authentication Failed",Toast.LENGTH_SHORT).show()
        }
    })

  3. Now, let's define the promptInfo variable.

    promptInfo = BiometricPrompt.PromptInfo.Builder()
    .setTitle("Biometric login for my app")
    .setSubtitle("Log in using your biometric credential")
    .setNegativeButtonText("Cancel")
    .build()

  4. Finally, we use the authenticate function to show our dialog when the button is clicked and give the biometricPrompt the promptInfo.

    binding.button.setOnClickListener {
        biometricPrompt.authenticate(promptInfo)
    }


And Result

GIF

You might also like...
Github-Api-Pagination-Example - Pagination 3 Example using Github Api

Github-Api-Pagination Pagination 3 Example using Github Api Tech Stack 100% Kotl

An Android Library that provides social login for 15 platforms within by RxJava2, Kotlin and Firebase Authentication.
An Android Library that provides social login for 15 platforms within by RxJava2, Kotlin and Firebase Authentication.

RxSocialLogin The license information for logo is located at the bottom of the document. These instructions are available in their respective language

ATH Sample is a sample Authentication and Authorization Application with Kotlin Language and MVVM architecture.
ATH Sample is a sample Authentication and Authorization Application with Kotlin Language and MVVM architecture.

ATH Sample ATH Sample is a sample Authentication and Authorization Application with Kotlin Language and MVVM architecture. Overview ATH Sample is a sa

✨ Social network app made with Android Compose, full Kotlin, Firebase Authentication, Storage and Firestore 🚀
✨ Social network app made with Android Compose, full Kotlin, Firebase Authentication, Storage and Firestore 🚀

Your friends, for real. Share daily random moments with your friends and discover who they really are. ✨ Instant Instant is a social media actually un

Implementing JWT token authentication on Android with Clean Architecture
Implementing JWT token authentication on Android with Clean Architecture

Implementando autenticação com token JWT no Android com Clean Architecture Implementar autenticação com Token JWT no Android não é uma tarefa fácil. É

BluePass extracts two factor authentication codes (2FA) from SMS and sends them to a paired device via Bluetooth RFCOMM.
BluePass extracts two factor authentication codes (2FA) from SMS and sends them to a paired device via Bluetooth RFCOMM.

BluePass extracts two factor authentication codes (2FA) from SMS and sends them to a paired device via Bluetooth RFCOMM.

Firebase Authentication plugin for Ktor framework.

Firebase Authentication is a Ktor plugin which verifies requests authorized by a Firebase Auth Id Token.

Projeto de Prova Semestral. Aplicativo Android com login e registro utilizando Firebase Authentication e consumo de API com Retrofit.
Projeto de Prova Semestral. Aplicativo Android com login e registro utilizando Firebase Authentication e consumo de API com Retrofit.

Ocean-Tech-Android Projeto de Prova Semestral. Aplicativo Android com login e cadastro utilizando Firebase Authentication e consumo de API com Retrofi

This is a Movie API app in which data is fetched online from the TMDB site using API authentication.

Movie-API This is a Movie API app in which data is fetched online from the TMDB site using API authentication. MVVM model is used for Database Managme

Simple implementation of a login made with jetpack compose and verifying its authentication through a REST API using retrofit
Simple implementation of a login made with jetpack compose and verifying its authentication through a REST API using retrofit

Simple Login/Auth + Jetpack Compose + Retrofit Demo 📱 Json Object Request 📑 Re

Android library for Tesla Authentication based on Tesla JSON API (Unofficial)

TeslaAndroidAuth Lightweight Android library for Tesla SSO Authentication based

PhoneAuthentication - Firebase Phone Authentication For Android
PhoneAuthentication - Firebase Phone Authentication For Android

PhoneAuthentication Firebase Phone Authentication. Android Clean Architecture us

FirebaseAuthentication - Login/Register Android Application using Firebase Authentication

FireBaseAuthentication This is a Firebase Authentication Application which will

The application uses Firebase Authentication and Realtime Database services
The application uses Firebase Authentication and Realtime Database services

This is a Chik-Chika. Chick-Chicka is android app, which is based on popular social network - Twitter. The application uses Firebase Authentication and Realtime Database services.

Authenticator Pro is a free open-source two factor authentication app for Android
Authenticator Pro is a free open-source two factor authentication app for Android

Authenticator Pro Authenticator Pro is a free open-source two factor authentication app for Android. It features encrypted backups, icons, categories

Login-and-Signup - Simple Login-and-Signup with authentication using Firebase API
Login-and-Signup - Simple Login-and-Signup with authentication using Firebase API

Simple Login-and-Signup with authentication using Firebase API. Log in Sign Up

Simple authentication provider for Ktor that verifies presence of the API key in the header

Ktor API Key Authentication Provider Simple authentication provider for Ktor that verifies presence of the API key in the header. Useful if you want t

Firebase Authentication and realtime database implementation in Android Kotlin

Androidfirebaseauthentication Firebase is Google’s mobile platform that helps you develop high-quality apps and provides hosted backend services such

A sample Android app that demonstrates how to use Firebase Authentication, Crashlytics, Cloud Firestore and Hilt with Jetpack Compose UI

showcase.mp4 Make it So This is a sample Android app that demonstrates how to use Firebase Authentication, Crashlytics, Cloud Firestore and Hilt with

Owner
Adem ATİCİ
Firat University - Software Engineering
Adem ATİCİ
The easy way to use biometric authentication in your Flutter app. Supports Fingerprint, FaceID and Iris.

BiometricX The easy way to use biometric authentication in your Flutter app. Supports Fingerprint, FaceID and Iris. Demo APK. Starting $ flutter pub a

Salman S 13 Dec 15, 2022
Fingerprint Biometric Authentication Android

Fingerprint-BiometricAuthentication-Android Preview Authentication Succeeded Aut

mohamed tamer 4 Apr 12, 2022
POC Simulate Backend Biometric Authentication with AIDL (client app/server app)

poc-simulate-bio-auth-aidl POC Simulate Backend Biometric Authentication with AIDL (client app/server app) #How to use Install server app and run Inst

gundamD 0 Dec 30, 2021
A Material design Android pincode library. Supports Fingerprint.

LolliPin A Lollipop material design styled android pincode library (API 14+) To include in your project, add this to your build.gradle file: //Loll

Omada Health 1.6k Nov 25, 2022
Extract SHA-256 Certificate Fingerprint from hostname or certificate (.crt, .der or .pem) file

Certificate Fingerprint Extractor This tool extract SHA-256 Certificate Fingerprint from hostname or certificate (.crt, .der or .pem) file. In order t

Reign 1 Nov 8, 2022
This is an Android project allowing you to use the advanced biometric authorization features.

PLEASE NOTE: If your project has minSDK 23 and should support only basic Fingerprint Authorization on most devices - take a look first at the AndroidX

Sergej Komlach 82 Dec 30, 2022
BiometricAuth - A simple project to show biometric authenticaation in android

BiometricAuth a simple project to show biometric authenticaation in android link

richard ndemo 0 Feb 16, 2022
An Android app that gives you a password generated by a given phrase with a custom algorithm, it also has password and biometric security.

An Android app that gives you a password generated by a given phrase with a custom algorithm, it also has password and biometric security.

Marcos Ariel Paccor 1 May 23, 2022
Simple spring boot JWT authentication example

JWT authentication This an example how to set up jwt authentication with access and refresh token. Related blog post is available here: https://coding

null 1 Feb 9, 2022
Example of migrating from Dagger to Hilt with a real service/repository example

DaggerToHilt Overview This repo provides a real example of using Hilt for dependency injection. It hits endpoints provided by the Movie Database, and

null 0 Nov 29, 2021