gpt4 book ai didi

java - Firebase 身份验证 : how to get current user's Password?

转载 作者:行者123 更新时间:2023-11-30 06:46:12 25 4
gpt4 key购买 nike

我是 firebase Authentication 的新手..所以,我正在创建一个带有配置文件的基本应用程序,我做了一个 Activity 来编辑用户的基本信息,例如 DisplayNameEmail...,我不想添加更改密码的功能,但首先,我不想检查当前用户的密码并将其与 进行比较来自 InputEditText 的字符串,用户在更改密码之前必须知道他的当前密码。

编辑:我要问的是我要求用户写下他当前的 Password 以便能够将其更改为新密码以减少黑客攻击或类似的事情,例如 Facebook 当您尝试更改 EmailPassword 甚至 Name 时,它会询问您当前的 Password

![Example

最佳答案

来自Firebase documentation :

Some security-sensitive actions—such as deleting an account, setting a primary email address, and changing a password—require that the user has recently signed in.

If you perform one of these actions, and the user signed in too long ago, the action fails and throws FirebaseAuthRecentLoginRequiredException. When this happens, re-authenticate the user by getting new sign-in credentials from the user and passing the credentials to reauthenticate. For example:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

// Get auth credentials from the user for re-authentication. The example below shows
// email and password credentials but there are multiple possible providers,
// such as GoogleAuthProvider or FacebookAuthProvider.
AuthCredential credential = EmailAuthProvider
.getCredential("user@example.com", "password1234");
// Prompt the user to re-provide their sign-in credentials
user.reauthenticate(credential)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Log.d(TAG, "User re-authenticated.");
}
});

关于java - Firebase 身份验证 : how to get current user's Password?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47910898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com