电子邮件不存在时 Firebase 重置密码

And*_*diM 2 android forgot-password firebase firebase-authentication

我正在开发一个带有 Firebase 用户身份验证的 Android 应用程序。我面临的问题是我从用户那里获取电子邮件和密码,然后将该用户创建到 firebase 中。我没有验证用户输入的电子邮件。现在我想实现重置密码功能。为此,Firebase 提供了 ResetPassword 方法并向该特定用户发送重置密码电子邮件。但问题是,如果电子邮件不存在那我们该怎么办?

这是我用来在 Firebase 中注册用户的代码:

private void registerUser(){

        //creating a new user
        firebaseAuth.createUserWithEmailAndPassword("user email here", "user password here")
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {

                        //checking if success
                        if(task.isSuccessful()){
                            //display some message here 
                        }else{
                            //display some message here 
                        }

                    }
                });

    }
Run Code Online (Sandbox Code Playgroud)

如果此功能有任何替代选项,请告诉我。谢谢。

Fra*_*len 5

另一种方法是使用 Firebase Admin SDK 更改用户的密码。来自更新用户信息的文档

updateUser()方法允许您修改现有用户的数据。它接受uid用户更新以及包含UserRecord要更新的属性的对象:

admin.auth().updateUser(uid, {
  email: "modifiedUser@example.com",
  emailVerified: true,
  password: "newPassword",
  displayName: "Jane Doe",
  photoURL: "http://www.example.com/12345678/photo.png",
  disabled: true
})
  .then(function(userRecord) {
    // See the UserRecord reference doc for the contents of userRecord.
    console.log("Successfully updated user", userRecord.toJSON());
  })
  .catch(function(error) {
    console.log("Error updating user:", error);
  });
Run Code Online (Sandbox Code Playgroud)

和:

密码-字符串- 用户的新的原始、未散列的密码。长度必须至少为六个字符。

Firebase Admin SDK 的这一部分目前仅在 Node.js 中可用。但如果您还没有 Node.js 服务器,您可以在Cloud Functions for Firebase中实现该功能。