热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在FirebaseforAndroid中忘记密码-ForgotpasswordinFirebaseforAndroid

IbelievethereisawayforchangingyourpasswordinFirebasebutisthereawaywheretheuserfo

I believe there is a way for changing your password in Firebase but is there a way where the user forgets the password and can be assigned a new one or re-authenticated using email or SMS OTP. I checked out on the net but couldn't seem to find one.

我相信有一种方法可以在Firebase中更改您的密码,但有一种方法可以让用户忘记密码,并可以分配一个新密码或使用电子邮件或短信OTP重新进行身份验证。我在网上查了一下但似乎找不到一个。

If there is a way how can it be implemented, what all function calls need to be made. Could you direct me with an example.

如果有一种方法可以实现,那么需要进行所有函数调用。你能用一个例子指导我吗?

6 个解决方案

#1


25  

It sounds like you're looking to send a password reset email. See this example from the Firebase documentation:

听起来你正在寻找密码重置电子邮件。从Firebase文档中查看此示例:

FirebaseAuth.getInstance().sendPasswordResetEmail("user@example.com")
    .addOnCompleteListener(new OnCompleteListener() {
        @Override
        public void onComplete(@NonNull Task task) {
            if (task.isSuccessful()) {
                Log.d(TAG, "Email sent.");
            }
        }
    });

#2


8  

Reset Android FireBase Password

重置Android FireBase密码

Java File

Java文件

    public class ResetPasswordActivity extends AppCompatActivity {

    private EditText inputEmail;

    private Button btnReset, btnBack;

    private FirebaseAuth auth;

    private ProgressBar progressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_reset_password);

        inputEmail = (EditText) findViewById(R.id.email);

        btnReset = (Button) findViewById(R.id.btn_reset_password);

        btnBack = (Button) findViewById(R.id.btn_back);

        progressBar = (ProgressBar) findViewById(R.id.progressBar);

        auth = FirebaseAuth.getInstance();

        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        btnReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String email = inputEmail.getText().toString().trim();

                if (TextUtils.isEmpty(email)) {
                    Toast.makeText(getApplication(), "Enter your registered email id", Toast.LENGTH_SHORT).show();
                    return;
                }

                progressBar.setVisibility(View.VISIBLE);

                auth.sendPasswordResetEmail(email)

                        .addOnCompleteListener(new OnCompleteListener() {
                            @Override
                            public void onComplete(@NonNull Task task) {
                                if (task.isSuccessful()) {
                                    Toast.makeText(ResetPasswordActivity.this, "We have sent you instructions to reset your password!", Toast.LENGTH_SHORT).show();
                                } else {
                                    Toast.makeText(ResetPasswordActivity.this, "Failed to send reset email!", Toast.LENGTH_SHORT).show();
                                }

                                progressBar.setVisibility(View.GONE);
                            }
                        });
            }
        });
    }

}

XML FILE

XML文件




    




        

        

        

            
        

        

        

#3


3  

This link to the docs should help you out:

此文档链接应该可以帮助您:

DOCUMENTATION

文档

In short, Firebase has a method to use called changePassword, follow the link to find out how to implement it.

简而言之,Firebase有一种方法可以使用名为changePassword的方法,按照链接查找如何实现它。

#4


2  

Copied and pasted of documentation:

复制并粘贴文档:

FirebaseAuth auth = FirebaseAuth.getInstance();
String emailAddress = "user@example.com";

auth.sendPasswordResetEmail(emailAddress)
        .addOnCompleteListener(new OnCompleteListener() {
            @Override
            public void onComplete(@NonNull Task task) {
                if (task.isSuccessful()) {
                    Log.d(TAG, "Email sent.");
                }
            }
        });

#5


1  

Below is the simple method to send the reset password link on user email address with progress dialog (sometime firebase took time to complete reset password request because of slow internet connection on client side, so progress dialog will be helpful)

下面是使用进度对话框在用户电子邮件地址上发送重置密码链接的简单方法(有时firebase需要时间来完成重置密码请求,因为客户端连接速度较慢,因此进度对话框将有所帮助)

public void resetUserPassword(String email){
        FirebaseAuth mAuth = FirebaseAuth.getInstance();
        final ProgressDialog progressDialog = new ProgressDialog(ForgotPasswordActivity.this);
        progressDialog.setMessage("verifying..");
        progressDialog.show();

        mAuth.sendPasswordResetEmail(email)
                .addOnCompleteListener(new OnCompleteListener() {
                    @Override
                    public void onComplete(@NonNull Task task) {
                        if(task.isSuccessful()){
                            progressDialog.dismiss();
                            Toast.makeText(getApplicationContext(), "Reset password instructions has sent to your email",
                                    Toast.LENGTH_SHORT).show();
                        }else{
                            progressDialog.dismiss();
                            Toast.makeText(getApplicationContext(),
                                    "Email don't exist", Toast.LENGTH_SHORT).show();
                        }
                    }
                }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                progressDialog.dismiss();
                Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
            }
        });
    }

#6


0  

If Kotlin is your language of choice you can use this:

如果Kotlin是您的首选语言,您可以使用:

val fAuth = FirebaseAuth.getInstance()
fAuth.sendPasswordResetEmail(email).addOnCompleteListener({ listener ->
        if (listener.isSuccessful) {
            // Do something when successful
        } else {
            // Do something when not successful
        }
})

推荐阅读
author-avatar
手机用户2602930645
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有