Giter Club home page Giter Club logo

biometricx's Introduction

BiometricX

The easy way to use biometric authentication in your Flutter app.
Supports Fingerprint, FaceID and Iris.

Demo APK.

Starting

$ flutter pub add biometricx

Configuration

Change your android MainActivity to extends FlutterFragmentActivity.

import io.flutter.embedding.android.FlutterFragmentActivity

// kotlin
class MainActivity: FlutterFragmentActivity() {
  ...
}
import io.flutter.embedding.android.FlutterFragmentActivity;

// java
class MainActivity extends FlutterFragmentActivity {
  ...
}

Usage

To check biometric type of your device.

BiometricType type = await BiometricX.type;

Here is the list of biometric types.

BiometricType.FACE
BiometricType.FINGERPRINT
BiometricType.IRIS
BiometricType.MULTIPLE
BiometricType.NONE
BiometricType.NO_HARDWARE
BiometricType.UNAVAILABLE
BiometricType.UNSUPPORTED

To check if your device can use biometric authentication.

bool isBiometricEnabled = await BiometricX.isEnabled;

To encrypt data using biometric authentication.

BiometricResult result = await BiometricX.encrypt({
  biometricKey: 'salkuadrat',
  message: 'This is a very secret message',
});

if (result.isSuccess && result.hasData) {
  // Keep this messageKey to decrypt your message.
  // This messageKey will be randomly generated by BiometricX plugin.
  String messageKey = result.data!;
} else {
  showToast(result.errorMsg, context: context);
}

If you need a persistent messageKey, you can supply it as parameter to encrypt.

BiometricResult result = await BiometricX.encrypt({
  biometricKey: 'salkuadrat',
  messageKey: 'secret_message', // use persistent messageKey
  message: 'This is a very secret message',
});

if (result.isSuccess && result.hasData) {
  // Keep this messageKey to decrypt your message.
  // This will be the same value as messageKey above ('secret_message')
  String messageKey = result.data!;
} else {
  showToast(result.errorMsg, context: context);
}

To decrypt data using biometric authentication.

// Use the same biometricKey that is used to encrypt your message.
// Use messageKey that you get from [BiometricX.encrypt].
BiometricResult result = await BiometricX.decrypt({
  biometricKey: 'salkuadrat',
  messageKey: messageKey,
});

if (result.isSuccess && result.hasData) {
  // This will contains your original message.
  String message = result.data!;
} else {
  showToast(result.errorMsg, context: context);
}

To show custom message in your biometric prompt, method encrypt and decrypt have parameters you can use to change the biometric prompt dialog.

BiometricResult result = await BiometricX.encrypt({
  biometricKey: 'salkuadrat',
  message: 'This is a very secret message',
  title: 'Biometric Encryption',
  subtitle: 'Enter biometric credentials to encrypt your message',
  description: 'Scan fingerprint or face.',
  negativeButtonText: 'USE PASSWORD',
  confirmationRequired: true,
});
BiometricResult message = await BiometricX.decrypt({
  biometricKey: 'salkuadrat',
  messageKey: messageKey,
  title: 'Biometric Decryption',
  subtitle: 'Enter biometric credentials to decrypt your message',
  description: 'Scan fingerprint or face.',
  negativeButtonText: 'USE PASSWORD',
  confirmationRequired: true,
});

Example

Example project.
Demo APK.

biometricx's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.