GithubHelp home page GithubHelp logo

anitaa1990 / biometric-auth-sample Goto Github PK

View Code? Open in Web Editor NEW
247.0 14.0 143.0 197 KB

Add Biometric Authentication to any Android app

Java 100.00%
androidp android android-sdk android-sdk-library java biometricprompt android-architecture-components android-p android-permissions android-library

biometric-auth-sample's Introduction

Biometric-Auth-Sample

Add Biometric Authentication to any Android app

This library provides an easy way to implement fingerprint authentication without having to deal with all the boilerplate stuff going on inside.

API




How to integrate the library in your app?

Gradle Dependecy
dependencies {
        implementation(group: 'com.an.biometric', name: 'biometric-auth', version: '0.1.0', ext: 'aar', classifier: '')
}

Usage

new BiometricManager.BiometricBuilder(MainActivity.this)
                        .setTitle("Add a title")
                        .setSubtitle("Add a subtitle")
                        .setDescription("Add a description")
                        .setNegativeButtonText("Add a cancel button")
                        .build()
                        .authenticate(biometricCallback);

The BiometricCallback class has the following callback methods:

new BiometricCallback() {
              @Override
              public void onSdkVersionNotSupported() {
                     /*  
                      *  Will be called if the device sdk version does not support Biometric authentication
                      */
               }

               @Override
               public void onBiometricAuthenticationNotSupported() {
                     /*  
                      *  Will be called if the device does not contain any fingerprint sensors 
                      */
               }

               @Override
               public void onBiometricAuthenticationNotAvailable() {
                    /*  
                     *  The device does not have any biometrics registered in the device.
                     */
               }

               @Override
               public void onBiometricAuthenticationPermissionNotGranted() {
                      /*  
                       *  android.permission.USE_BIOMETRIC permission is not granted to the app
                       */
               }

               @Override
               public void onBiometricAuthenticationInternalError(String error) {
                     /*  
                      *  This method is called if one of the fields such as the title, subtitle, 
                      * description or the negative button text is empty
                      */
               }

               @Override
               public void onAuthenticationFailed() {
                      /*  
                       * When the fingerprint doesn’t match with any of the fingerprints registered on the device, 
                       * then this callback will be triggered.
                       */
               }

               @Override
               public void onAuthenticationCancelled() {
                       /*  
                        * The authentication is cancelled by the user. 
                        */
               }

               @Override
               public void onAuthenticationSuccessful() {
                        /*  
                         * When the fingerprint is has been successfully matched with one of the fingerprints   
                         * registered on the device, then this callback will be triggered. 
                         */
               }

               @Override
               public void onAuthenticationHelp(int helpCode, CharSequence helpString) {
                         /*  
                          * This method is called when a non-fatal error has occurred during the authentication 
                          * process. The callback will be provided with an help code to identify the cause of the 
                          * error, along with a help message.
                          */
                }

                @Override
                public void onAuthenticationError(int errorCode, CharSequence errString) {
                         /*  
                          * When an unrecoverable error has been encountered and the authentication process has 
                          * completed without success, then this callback will be triggered. The callback is provided 
                          * with an error code to identify the cause of the error, along with the error message. 
                          */
                 }
              });

biometric-auth-sample's People

Contributors

anitaa1990 avatar hassanmhd avatar mirjalal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

biometric-auth-sample's Issues

Crash in Android Version 7 API 24

java.lang.RuntimeException: Unable to start activity ComponentInfo{}: java.lang.RuntimeException: Failed to init Cipher
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6253)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.RuntimeException: Failed to init Cipher
at com.utils.fingerprint.BiometricManagerV23.initCipher(BiometricManagerV23.java:180)
at com.utils.fingerprint.BiometricManagerV23.displayBiometricPromptV23(BiometricManagerV23.java:55)

For some device the init Cipher doesn't work (API 23)

In some devices the init Cipher doesn't work you need change your code to:

Kotlin code:

private fun initCipher() : Boolean {
        try {
            cipher = Cipher.getInstance(
                KeyProperties.KEY_ALGORITHM_AES + "/"
                + KeyProperties.BLOCK_MODE_CBC + "/"
                + KeyProperties.ENCRYPTION_PADDING_PKCS7
            )
        } catch (e:NoSuchAlgorithmException) {
            throw RuntimeException("Failed to get Cipher", e)
        } catch (e: NoSuchPaddingException) {
            throw RuntimeException("Failed to get Cipher", e)
        }

        return try {
            keyStore?.load(null)
            sharedPreferences.getString("biometric_param", null)?.let {
                val key = keyStore?.getKey(KEY_NAME, null) as SecretKey
                if (it.isNotEmpty()) {
                    val arraysBytes = Base64.decode(it, Base64.NO_WRAP)
                    val ivParams = IvParameterSpec(arraysBytes)
                    cipher?.init(mode, key, ivParams)
                }
            } ?: run {
                cipher?.init(Cipher.ENCRYPT_MODE, generateKey())
                val ivParams = cipher?.parameters?.getParameterSpec(IvParameterSpec::class.java)
                ivParams?.iv?.let { iv ->
                    sharedPreferences.edit().apply {
                        putString(BIOMETRIC_PARAM, Base64.encodeToString(iv, Base64.NO_WRAP))
                    }
                }
            }
            true
        } catch (e: KeyPermanentlyInvalidatedException) {
            false
        } catch (e: Exception) {
            throw java.lang.RuntimeException("Failed to init Cipher", e)
        }
    }

Crash

Hi, error->
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.ActivityCompat" on path: DexPathList[[zip file ...
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/ActivityCompat;

In any case the attempt to help is appreciated, I wanted to simplify the project since I currently have a code for android P onwards and one for the previous ones (FingerprintManager) but unfortunately this does not work, so I will continue using my own code

attr/bottomSheetStyle Not Found

Please Help Me !!!

C:\Users\ado.gradle\caches\transforms-2\files-2.1\9cdcbf42f4209cf80a43ee68b3f804aa\jetified-biometric-auth-0.1.0\res\values\values.xml:28:5-31:13: AAPT: error: style attribute 'attr/bottomSheetStyle (aka com.gramedia.myfingerprint:attr/bottomSheetStyle)' not found.

[How to] Canceling fingerprint scanning ?

Fingerprint scanner doesn't stop scanning after choose the CANCEL option.
Step to reproduce

  1. Open App and clicked on Login button. This will open up the bottom bar with fingerprint scanning option
  2. Choose Cancel button.
  3. Cancel callback invoked successfully and able to see the prompt too.
  4. Fingerprint scanner still working in background. If user choose to put scan finger again, it prompt callback methods.

Looks like CancellationSignal object doesn't work with .authenticate method.

Display fingerprint dialog

Can't display the dialog without activity instance, I am trying to use your library to show fingerprint scan dialog inside a custom keyboard that doesn't have activity reference, is that possible

Style not found

Hey, i'm getting the following error when trying to use your package:
Output: error: resource style/Theme.Design.Light.BottomSheetDialog (aka org.mes:style/Theme.Design.Light.BottomSheetDialog) not found.

How can i fix this?

Localization issue in v23

When I switch the language from English to French all text works fine just Wrong fingerprint text is not changed to French. Any idea how to solve this?

Screen Shot 2022-08-10 at 10 57 13 PM

How to make the biometric dialog full screen?

I have requirement so that the dialog should cover the full screen so that user can't see the information behind.

Is there any possibility to do this?
I have tried changing in the actual code but didn't succeed.

Add License

Hi,

Thanks for the example, the lib and the good article

Note that if we want to use your SDK we need a license on it.

Could you please add one ?

Unable to Import

I am unable to import into system. Was working fine for a while.

implementation(group: 'com.an.biometric', name: 'biometric-auth', version: '0.1.0', ext: 'aar', classifier: '')

In activity:

image

Android Studio version 3.2.1.
Gradle version 4.6.
Compile SDK API 28 (Android 9 - Pie) - This is also the target
Min Sdk Version API23 (Android 6 - Marshmallow)
Build Tools Version 28.0.3

Enable to prevent device back button on Android 9 and above

I am implementing switchcompat when biometric is used.
When the biometric prompt is visible and without scanning fingerprint if user presses device back button, prompt gets dismissed.
How to prevent device back button when prompt is visible?
Need resolution asap.

Support for 3rd party

Is there some way you know about through which I can collect fingerprint information from the phone's fingerprint scanner and use it on a blockchain network for the authentication process. I want figure print also to be verified on a blockchain network. Would be glad if u certain resource you have for the same. Read your amazing article on medium.

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.