cordova通过指纹插件进行指纹验证

版权声明:本文为博主原创文章,转载须注明出处,博客地址:https://blog.csdn.net/wx13227855087 https://blog.csdn.net/wx13227855087/article/details/85004220

使用的插件: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>

猜你喜欢

转载自blog.csdn.net/wx13227855087/article/details/85004220