android - 使用系统密码进行身份验证

标签 android authentication

我找不到允许我在我的应用程序中使用用户在 Android 设备上设置的密码/pin/模式进行身份验证的 API。

有一个指纹身份验证 API,我可以使用它来要求 Android 对用户进行身份验证,但是没有密码 API 可以代替指纹来使用密码/pin/模式。

有没有办法让 Android 根据用户已经设置的密码/pin/模式在我的应用中进行身份验证?

最佳答案

如果您问“我怎样才能让系统重新验证用户身份?”,在 Android 5.0+ 上,这样的事情应该可行:

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 project 中看到正在使用的代码(稍作修改) .

如果你问“我怎样才能得到用户的密码/密码/图案供我自己使用?”,那是不可能的。

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

// 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  
        }  
    }  
}

关于android - 使用系统密码进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45718790/

相关文章:

android - Android 中的管道问题

authentication - cloud foundry cli登录代理

facebook - 使用 FB.login 的注册流程

android - 当我尝试以我在android中制作的登录表单编写内容时,发生了Android Soundpool错误

Android IAB 错误 - 需要身份验证

java - 通过 LdapExtLoginModule 针对 Active Directory 林 (LDAP_REFERRAL) 进行身份验证

authentication - Sonar 3.4 LDAP 身份验证与 Active Directory - NullPointer 异常

angular - Ionic 4 - AuthGuard 页面路由权限延迟

android - 使用 findViewById 对明显随机 View 的随机 ClassCastExceptions

android.hardware.Camera$EventHandler.handleMessage