Scan the fingerprint of your user with the TouchID sensor and other Fingerprint sensor
npm install cordova-plugin-fingerprint-id
$ cordova plugin add cordova-plugin-fingerprint-id
$ cordova prepare
`
The latest, from the master repo:
`
$ cordova plugin add <>
$ cordova prepare
`
TouchID.js is brought in automatically. There is no need to change or add anything in your html.
//TODO - Samsung Android Installation
3. Usage
First you'll want to check whether or not the user has a configured fingerprint scanner.
You can use this to show a 'log in with your fingerprint' button next to a username/password login form.
`js
window.plugins.touchid.isAvailable(
function() {alert('available!')}, // success handler: TouchID available
function(msg) {alert('not available, message: ' + msg)} // error handler: no TouchID available
);
`
If the onSuccess handler was called, you can scan the fingerprint.
There are two options: verifyFingerprint and verifyFingerprintWithCustomPasswordFallback.
The first method will offer a fallback option called 'enter passcode' which shows the default passcode UI when pressed.
The second method will offer a fallback option called 'enter password' (not passcode) which allows you to provide your own password dialog.
`js
window.plugins.touchid.verifyFingerprint(
'Scan your fingerprint please', // this will be shown in the native scanner popup
function(msg) {alert('ok: ' + msg)}, // success handler: fingerprint accepted
function(msg) {alert('not ok: ' + JSON.stringify(msg))} // error handler with errorcode and localised reason
);
`
The errorhandler of the method above can receive an error code of -2 which means the user pressed the 'enter password' fallback.
`js
window.plugins.touchid.verifyFingerprintWithCustomPasswordFallback(
'Scan your fingerprint please', // this will be shown in the native scanner popup
function(msg) {alert('ok: ' + msg)}, // success handler: fingerprint accepted
function(msg) {alert('not ok: ' + JSON.stringify(msg))} // error handler with errorcode and localised reason
);
`
This will render a button labelled 'Enter password' in case the fingerprint is not recognized.
If you want to provide your own label ('Enter PIN' perhaps), you can use awkwardly named function (added in version 3.1.0):
`js
window.plugins.touchid.verifyFingerprintWithCustomPasswordFallbackAndEnterPasswordLabel(
'Scan your fingerprint please', // this will be shown in the native scanner popup
'Enter PIN', // this will become the 'Enter password' button label
function(msg) {alert('ok: ' + msg)}, // success handler: fingerprint accepted
function(msg) {alert('not ok: ' + JSON.stringify(msg))} // error handler with errorcode and localised reason
);
`
You can copy-paste these lines of code for a quick test:
`html
`
//TODO - Samsung Android Usage
4. Security++
Since iOS9 it's possible to check whether or not the list of enrolled fingerprints changed since
the last time you checked it. It's recommended you add this check so you can counter hacker attacks
to your app. See this article for more details.
So instead of checking the fingerprint after isAvailable add another check.
In case didFingerprintDatabaseChange returns true you probably want to re-authenticate your user
before accepting valid fingerprints again.
`js
window.plugins.touchid.isAvailable(
// success handler; available
function() {
window.plugins.touchid.didFingerprintDatabaseChange(
function(changed) {
if (changed) {
// re-auth the user by asking for his credentials before allowing a fingerprint scan again
} else {
// call the fingerprint scanner
}
}
);
},
// error handler; not available
function(msg) {
// use a more traditional auth mechanism
}
);
``