android实现实名认证_如何在Android中实现生物特征认证

android实现实名认证

Many applications on your device store some type of private data that is to be protected by another unauthorized user (e.g. banking apps, finance apps, etc.). The best way to protect this type of data is through biometric authentication in the app. With a biometric lock, users who don’t have access to your password can’t open the app without the owner’s permission.

设备上的许多应用程序存储某种类型的私有数据,这些数据将由另一位未经授权的用户(例如,银行应用程序,金融应用程序等)保护。 保护此类数据的最佳方法是通过应用程序中的生物特征认证。 使用生物特征识别锁定后,没有所有者密码的用户将无法打开应用程序。

When I first heard about the concept of a biometric lock, I thought it would be hard to implement. In actuality, it was easy.

当我第一次听说生物识别锁的概念时,我认为很难实现。 实际上,这很容易。

Let’s go through a short demo for biometric authentication in Android.

让我们看一下简短的演示,以了解Android中的生物特征认证。

实作 (Implementation)

  1. Create a new project in Android Studio.

    在Android Studio中创建一个新项目。
  2. Add a dependency in the app build.gradle file.

    app build.gradle文件中添加一个依赖app build.gradle

  3. Add a button and text to your Main Activity.

    在您的主要活动中添加按钮和文字。
  4. Create the BiometricPrompt object in the MainActivity.kt file.

    MainActivity.kt文件中创建BiometricPrompt对象。

  5. Now we will make an object in Oncreate() and a boolean variable named isCapable that will return whether the device has biometric authentication or not.

    现在,我们将在Oncreate()创建一个对象,并创建一个名为isCapable的布尔变量,该布尔变量将返回设备是否具有生物识别身份验证。

  6. Using the BiometricPrompt object, add callbacks for authentication errors, successes, and failures.

    使用BiometricPrompt对象,添加用于身份验证错误,成功和失败的回调。

There are mainly three callbacks for biometric authentication:

生物识别身份验证主要有三个回调:

  • onAuthenticationError

    onAuthenticationError

  • onAuthenticationSucceeded

    onAuthenticationSucceeded

  • onAuthenticationFailed

    onAuthenticationFailed

There are many possible reasons for an authentication error (e.g. the password is incorrect, something went wrong with the biometric lock, etc.). The same goes for authentication success and authentication failure. There are many possibilities.

身份验证错误的原因可能很多(例如密码不正确,生物特征识别锁出了毛病等)。 身份验证成功和身份验证失败也是如此。 有很多可能性。

You can use a unique code to show an error or any message as per the app requirements.

您可以根据应用要求使用唯一的代码显示错误或任何消息。

You can find all the code and callback types in Android’s documentation.

您可以在Android文档中找到所有代码和回调类型。

7. Add the biometric PromptInfo object.

7.添加生物PromptInfo对象。

  • You can edit setTitle and setSubtitle as per the message you want on the lock screen.

    您可以根据需要在锁定屏幕上显示的消息来编辑setTitlesetSubtitle

  • setDeviceCredentialAllowed will allow the user to use options aside from biometric authentication to unlock the app (e.g. password, number password, or pattern lock).

    setDeviceCredentialAllowed将允许用户使用生物识别身份验证以外的选项来解锁应用程序(例如密码,数字密码或图案锁定)。

  • setConfirmationRequired will confirm the user credentials given, but only when the face lock is active.

    setConfirmationRequired将确认给定的用户凭据,但仅当面部锁定处于活动状态时。

8. The final step is the button click event on which the app lock’s dialog is opened.

8.最后一步是打开应用程序锁对话框的按钮单击事件。

And that’s it! Biometric authentication has been implemented.

就是这样! 生物识别认证已经实施。

Here is a look at the demo:

这里是一个演示:

Image for post

翻译自: https://medium.com/better-programming/how-to-implement-biometric-authentication-in-android-a1da36d61b1e

android实现实名认证

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值