react-native-fingerprint-scanner icon indicating copy to clipboard operation
react-native-fingerprint-scanner copied to clipboard

Authentication was not successful because the user failed to provide valid credentials - throws randomly.

Open dekameron22 opened this issue 6 years ago • 18 comments

FingerprintScanner.authenticate({
        onAttempt: this.handleAuthenticationAttempted
      })
        .then(() => {
          console.log('success');
          this.setState({ errorMessage: undefined });
          this.handleFingerprintDismissed(true);
        })
        .catch(error => {
          this.setState({ errorMessage: error });
          console.log('errorr', error);
        });

sometimes inside componentdidmount this method returns error

Authentication was not successful because the user failed to provide valid credentials.

even if user didn't scan finger.

dekameron22 avatar May 31 '18 13:05 dekameron22

+1

IsracardTeam avatar Jun 20 '18 10:06 IsracardTeam

+1 Samsung S8

SaniokUA avatar Jul 09 '18 16:07 SaniokUA

I have the same issue, though less random - on Android. I use an auto logout feature. After auto logout is triggered, the fingerprint scanner shows Authentication was not successful because the user failed to provide valid credentials To reset, I need to quit the app and restart. Is there a way to programmatically reset the fingerprint scanner?

kenkotch avatar Jul 25 '18 23:07 kenkotch

I solved the issue on my end. If FingerprintScanner.release() doesn't get called after you authenticate and before you use again it causes the issue. componentWillUnmount() isn't getting called for a variety of reasons (bugs in RN modal) so instead in componentDidMount() I call FingerprintScanner.release() before FingerprintScanner.isSensorAvailable() and .authenticate()

I'm also using react-native-router-flux. Previously I was using Actions.nextView() which was causing some problems. For my use I now use Actions.replace("nextView")

kenkotch avatar Aug 06 '18 01:08 kenkotch

Getting the same error. FingerprintScanner.release() does nothing at all.

C0dekid avatar Aug 14 '18 07:08 C0dekid

+1

yoavprat avatar Sep 15 '18 09:09 yoavprat

Hi all, I've recently been added as a collaborator on this repo and am getting up to speed on the different issues.

I think I understand the bug report, however, based on @kenkotch's posted work around I'm not sure what next steps are. I suppose one approach would be to always call .release() on android when authentication succeeds or fails? If anyone has a potential fix to PR, would definitely appreciate it!

phillbaker avatar Sep 15 '18 23:09 phillbaker

Hi,

calling the .release() doesn't fix it for me. :(

it looks like the Java's onHostDestroy is never called from my understanding. and then when you try to use the fingerprint again the old context is being thrown to the native module and to the React Native Bridge.

[update]

after reading the Android Fingerprint docs, you need to wait 30+ seconds after 5 failed attempts. I will add a rate limiter from my side and will let you know.

yoavprat avatar Sep 16 '18 03:09 yoavprat

@yoavapi thanks for the update. That sounds like it'd be good to add to the example app in this repo and/or to the readme. Any interest in doing a PR?

phillbaker avatar Sep 16 '18 21:09 phillbaker

This issue has been there for a while. Is someone working on it? I too face the same issue where the fingerprint scanner throws unauthorised error.

soumyamishra89 avatar Nov 20 '18 09:11 soumyamishra89

@soumyamishra89 were you able to try @yoavapi's suggested workaround:

after reading the Android Fingerprint docs, you need to wait 30+ seconds after 5 failed attempts. I will add a rate limiter from my side and will let you know.

Alternatively, it looks like this PR: https://github.com/hieuvp/react-native-fingerprint-scanner/pull/44 might also help, specifically, the changes to bring in onStartFailedByDeviceLocked.

phillbaker avatar Nov 29 '18 22:11 phillbaker

@phillbaker The issue is not when the user has failed attempts. The issue is when the app is opened for the first time, the user has not attempted to unlock with fingerprint and still it shows failed attempt. May be the PR: #44 might help.

soumyamishra89 avatar Nov 30 '18 09:11 soumyamishra89

any update on this issue?

soumyamishra89 avatar Dec 17 '18 15:12 soumyamishra89

facing the same issue. calling FingerprintScanner.release() before authentication is not working.

To add to this: The issue is when the app is opened for the first time, the user has not attempted to unlock with fingerprint and still it shows failed attempt. Open the app -> minimize it -> bring the app in foreground -> bang there is an error.

To my surprise I was getting the same error on device lock. but when is used react-native-restart to restart the app, the error was not replicated. but error persists on app minimise.

Please fix this bug.

viv3kk avatar Feb 01 '19 15:02 viv3kk

A workaround although a nasty one. Restart the app twice.

_handleAppStateChange = (nextAppState) => {
console.log(this.state.appState,nextAppState)

if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
    console.log('App has come to the foreground!');  
    RNRestart.Restart();  // Restart app once  , works like a charm in case phone is locked and unlocked
}
this.setState({appState: nextAppState});
};
FingerprintScanner
.isSensorAvailable()
.then((biometryType) => {
FingerprintScanner
.authenticate({ onAttempt: self.handleAuthenticationAttempted })
.then(() => {
// do your stuff
})
.catch((error) => {
if(error.message == 'Authentication was not successful because the user failed to provide valid credentials.' && this.restart_count == 0){
this.restart_count == 1; // check to handle looping issue
RNRestart.Restart(); // Restart the app twice to handle is particular case
}
self.setState({ errMsg: error.message });

    });

viv3kk avatar Feb 01 '19 16:02 viv3kk

@soumyamishra89 , @phillbaker , @yoavapi any update on above ?

dg92 avatar Feb 05 '19 18:02 dg92

@dg92 i tried to create a PR by updating the android library used for this one...but could not make it work as the updated android library uses androidx and if i upgrade to androidx then i have other libraries which do not support it yet and throws error... So created my own native implementation for now and testing if it works fine.

but i am not a contributor to this library so also waiting for updates from the contributors.

soumyamishra89 avatar Feb 08 '19 10:02 soumyamishra89

Hi, this issue happens when you exit the react native app through the android back button

I had solved this issue by using the BackHandler module

after that, I had used the react-native-exit-app package .. which forces the app to be fully killed not like the backHandler.exitApp() method

below you will find the code implementation when the back button is pressed

carbon

Now just enter the app again ... and the issue is SOLVED 💃

Baraa-bi avatar Sep 12 '19 15:09 Baraa-bi