Flutter Local Authentication using Biometrics – Face ID, Touch ID, Fingerprint

As the Flutter community grows, it is also creating a variety of libraries to support the native functionality. When a user’s fingerprints, facial characteristics, or voice are used to authenticate their identification, this is referred to as biometric…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by mrcflorian

As the Flutter community grows, it is also creating a variety of libraries to support the native functionality. When a user’s fingerprints, facial characteristics, or voice are used to authenticate their identification, this is referred to as biometric authentication. Let’s see how you can implement Local Authentication for Biometrics in Flutter.

image

Almost every phone on the market today has some kind of biometric authentication. We no longer need to type in a password since we can just press our fingerprints to verify our identity. Fingerprint Authentication in Flutter Apps is the topic of this essay.

Import local_auth Package

First off, We include local_auth package into our pubspec.yaml file so we can use it in our project

dependencies:
  flutter:
    sdk: flutter
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.5
  local_auth: ^2.1.2
  local_auth_android: ^1.0.14
  local_auth_ios: ^1.0.10

How to Use local_auth

This Flutter plugin enables us to authenticate users locally, on the device, using this feature.

To check whether there is local authentication available on this device or not, call canCheckBiometrics (if you need biometrics support) and/or isDeviceSupported() (if you just need some device-level authentication):

final LocalAuthentication auth = LocalAuthentication();
final bool canAuthenticateWithBiometrics = await auth.canCheckBiometrics;
final bool canAuthenticate =
    canAuthenticateWithBiometrics || await auth.isDeviceSupported();

Don’t forget to import the package into your file like this:

import 'package:local_auth/local_auth.dart';

Currently the following biometric types are implemented:

  • BiometricType.face
  • BiometricType.fingerprint
  • BiometricType.weak
  • BiometricType.strong

Enrolled Biometrics

canCheckBiometrics indicates whether hardware support is available, not whether the device has any biometrics enrolled. To get a list of enrolled biometrics, call getAvailableBiometrics().

The types are device-specific and platform-specific, and other types may be added in the future, so when possible you should not rely on specific biometric types and only check that some biometric is enrolled:

final List<BiometricType> availableBiometrics =
await auth.getAvailableBiometrics();

if (availableBiometrics.isNotEmpty) {
  // Some biometrics are enrolled.
}

if (availableBiometrics.contains(BiometricType.strong) ||
    availableBiometrics.contains(BiometricType.face)) {
  // Specific types of biometrics are available.
  // Use checks like this with caution!
}

Options

authenticate() method uses biometric authentication when possible, but also allows fallback to pin, pattern, or passcode.

For more advanced features, check out the original post on how to implement local authentication for biometrics in Flutter


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by mrcflorian


Print Share Comment Cite Upload Translate Updates
APA

mrcflorian | Sciencx (2022-11-02T02:55:30+00:00) Flutter Local Authentication using Biometrics – Face ID, Touch ID, Fingerprint. Retrieved from https://www.scien.cx/2022/11/02/flutter-local-authentication-using-biometrics-face-id-touch-id-fingerprint/

MLA
" » Flutter Local Authentication using Biometrics – Face ID, Touch ID, Fingerprint." mrcflorian | Sciencx - Wednesday November 2, 2022, https://www.scien.cx/2022/11/02/flutter-local-authentication-using-biometrics-face-id-touch-id-fingerprint/
HARVARD
mrcflorian | Sciencx Wednesday November 2, 2022 » Flutter Local Authentication using Biometrics – Face ID, Touch ID, Fingerprint., viewed ,<https://www.scien.cx/2022/11/02/flutter-local-authentication-using-biometrics-face-id-touch-id-fingerprint/>
VANCOUVER
mrcflorian | Sciencx - » Flutter Local Authentication using Biometrics – Face ID, Touch ID, Fingerprint. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/02/flutter-local-authentication-using-biometrics-face-id-touch-id-fingerprint/
CHICAGO
" » Flutter Local Authentication using Biometrics – Face ID, Touch ID, Fingerprint." mrcflorian | Sciencx - Accessed . https://www.scien.cx/2022/11/02/flutter-local-authentication-using-biometrics-face-id-touch-id-fingerprint/
IEEE
" » Flutter Local Authentication using Biometrics – Face ID, Touch ID, Fingerprint." mrcflorian | Sciencx [Online]. Available: https://www.scien.cx/2022/11/02/flutter-local-authentication-using-biometrics-face-id-touch-id-fingerprint/. [Accessed: ]
rf:citation
» Flutter Local Authentication using Biometrics – Face ID, Touch ID, Fingerprint | mrcflorian | Sciencx | https://www.scien.cx/2022/11/02/flutter-local-authentication-using-biometrics-face-id-touch-id-fingerprint/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.