1. 程式人生 > >cordova通過指紋外掛進行指紋驗證

cordova通過指紋外掛進行指紋驗證

使用的外掛:cordova-plugin-android-fingerprint-auth

新增外掛:cordova plugin add cordova-plugin-android-fingerprint-auth

程式碼如下:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
     <script src="cordova.js"></script>
<script>

var encryptConfig = {
    clientId: "myAppName",
    username: "currentUser",
    password: "currentUserPassword"
}; 

 function showAuth(){
    FingerprintAuth.encrypt(encryptConfig, successCallback, errorCallback);
 }

function successCallback(result) {
    console.log("successCallback(): " + JSON.stringify(result));
    if (result.withFingerprint) {
        console.log("Successfully encrypted credentials.");
        console.log("Encrypted credentials: " + result.token);  
    } else if (result.withBackup) {
        console.log("Authenticated with backup password");
    }
}
 
function errorCallback(error) {
    if (error === FingerprintAuth.ERRORS.FINGERPRINT_CANCELLED) {
    alert("e1");
        console.log("FingerprintAuth Dialog Cancelled!");
    } else {
    alert("e2");
        console.log("FingerprintAuth Error: " + error);
    }
}
</script>
  </head>
  <body>
    <input type="button" value="指紋" onclick="showAuth()"><br/>
  </body>
</html>