我想为我的应用程序实现更改密码功能.
我在build.gradle文件中包含了com.Google.firebase:firebase-auth:9.0.2,到目前为止,在我尝试实现更改密码功能之前,一切正常.
我发现FirebaseUser对象有一个updatePassword方法,该方法将新密码作为参数.我可以使用这种方法并自己实现验证.但是,我需要用户的当前密码与输入的密码进行比较,我找不到获取密码的方法.
我还在Firebase对象上找到另一个method,它接受旧密码,新密码和处理程序.问题是我还需要包含com.firebase:firebase-clIEnt-androID:2.5.2来访问这个类,当我尝试这个方法时,我会遇到以下错误:
Projects created at console.firebase.Google.com must use the new Firebase Authentication SDKs available from firebase.Google.com/docs/auth/
觉得我在这里错过了一些东西.实施此建议的方法是什么?什么时候使用什么依赖?
解决方法:
我在Firebase docs中找到了一个方便的例子:
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 credentialsuser.reauthenticate(credential) .addOnCompleteListener(new OnCompleteListener<VoID>() { @OverrIDe public voID onComplete(@NonNull Task<VoID> task) { if (task.isSuccessful()) { user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<VoID>() { @OverrIDe public voID onComplete(@NonNull Task<VoID> task) { if (task.isSuccessful()) { Log.d(TAG, "Password updated"); } else { Log.d(TAG, "Error password not updated") } } }); } else { Log.d(TAG, "Error auth Failed") } } });
总结 以上是内存溢出为你收集整理的使用Firebase for Android更改密码全部内容,希望文章能够帮你解决使用Firebase for Android更改密码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)