使用系统密码进行身份验证 [英] Use System Passcode For Authentication

查看:163
本文介绍了使用系统密码进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到可以让我利用用户在Android设备上设置的用于在我的应用中进行身份验证的密码/密码/样式的API.

I cannot find an API that will allow me to tap into the password/pin/pattern the user has set up on an Android device for authentication in my app.

我可以使用一个指纹认证API来要求Android对用户进行身份验证,但是没有密码API可以使用密码/密码/图案代替指纹.

There is a Fingerprint Authentication API that I can use to ask Android to authenticate a user, but there is no passcode API to tap into the password/pin/pattern instead of fingerprint.

是否可以根据用户已经设置的密码/密码/样式要求Android在我的应用中进行身份验证?

Is there a way to ask Android to authenticate in my app based upon the password/pin/pattern the user already has set up?

推荐答案

在Android 5.0及更高版本上,如果您问我如何要求系统重新验证用户身份?",则应该可以执行以下操作:

If you are asking "how can I ask the system to re-authenticate the user?", on Android 5.0+, something like this should work:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
    KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);

    if (km.isKeyguardSecure()) {
        Intent authIntent = km.createConfirmDeviceCredentialIntent(getString(R.string.dialog_title_auth), getString(R.string.dialog_msg_auth));
        startActivityForResult(authIntent, INTENT_AUTHENTICATE);
    }
}

您可以在 the andOTP项目中看到正在使用的代码(稍作修改).

You can see that code in use (with slight modifications) in the andOTP project.

如果您问我如何获得自己使用的用户密码/密码/图案?",那是不可能的.

If you are asking "how can I get the user's password/pin/pattern for my own use?", that is not possible.

使用它来查看用户是否成功通过身份验证:

Use this to see if the user successfully authenticated:

// call back when password is correct  
@Override  
protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == INTENT_AUTHENTICATE) {  
        if (resultCode == RESULT_OK) {  
            //do something you want when pass the security  
        }  
    }  
}

这篇关于使用系统密码进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆