Firebase身份验证:如何获取当前用户的密码? [英] Firebase Authentication : how to get current user's Password?

查看:104
本文介绍了Firebase身份验证:如何获取当前用户的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 firebase身份验证的新手..因此,我正在使用配置文件创建一个基本应用程序,我进行了一项活动来编辑用户的基本信息,例如DisplayNameEmail ...,我不想添加更改密码的功能,但首先,我不想检查当前用户的密码并将其与用户必须知道的InputEditText中的String进行比较他的当前密码,然后再进行更改.

i'm new to firebase Authentication.. so, i'm creating a basic app with a profile, i've made an activity to edit basic informations of the user such as DisplayName and Email... , i wan't to add the capability of changing passwords, but first , i wan't to check current user's password and compare it to a String from an InputEditText that the user must know his current password before changing it.

我要问的是我要用户写他当前的Password以便能够将其更改为新的Password,以减少黑客入侵或类似的事情,例如在尝试尝试Facebook时更改它要求您提供当前PasswordEmailPassword甚至Name.

EDIT : the thing i'm asking about is i ask the user to write his current Password in order to be able to change it to a new one to reduce hacking or something like that, like on Facebook when you're trying to change the Email or Password or even the Name it asks you for your current Password.

推荐答案

来自 Firebase文档:

一些对安全敏感的操作-例如删除帐户,设置主电子邮件地址和更改密码-要求用户最近登录.

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.

如果您执行以下操作之一,并且用户登录时间过长,则该操作将失败并引发FirebaseAuthRecentLoginRequiredException.发生这种情况时,请通过从用户获取新的登录凭据并传递凭据以进行重新身份验证来对用户进行重新身份验证.例如:

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.");
        }
    });

这篇关于Firebase身份验证:如何获取当前用户的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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