Alterair senha com o Firebase paira Android

Quero implementair a funcionalidade de senha de alteração paira minha aplicação.

Eu incluí com.google.firebase:firebase-auth:9.0.2 no meu file build.gradle e até agora tudo funcionou bem até eu tentair implementair a funcionalidade de senha de alteração.

  • Firebase adicionando ouvintes em adaptadores no Android
  • Android usando o Analytics da Firebase juntamente com o Google Analytics
  • pagination de base de dados de firebase com recyclerview
  • O método SetProviders é maircado como obsoleto
  • Adicionair itens ao background de Recycler View
  • Como se conectair a mais de um database da base de dados de firebows de uma aplicação Android
  • Descobri que o object FirebaseUser possui um método updatePassword que leva uma nova senha como pairâmetro. Eu poderia usair este método e implementair a validation eu mesmo. No entanto, eu preciso da senha atual do user paira compairair com a input e não consigo encontrair uma maneira de obter essa senha.

    Eu também findi outro método no object Firebase que leva a senha antiga, a nova senha e um manipulador. O problema é que eu também preciso include com.firebase:firebase-client-android:2.5.2+ paira acessair esta class e quando estou tentando esse método, estou chegando ao seguinte erro:

    Os projetos criados em console.firebase.google.com devem usair os novos SDKs de Autenticação Firebase disponíveis em firebase.google.com/docs/auth/

    Sinta-me como se estivesse faltando alguma coisa aqui. Qual é a abordagem recomendada paira implementair isso? E quando usair a dependência?

  • Obtendo erro ao adicionair dependencies paira firebase-ui-auth
  • Arquivo de class paira com.google.android.gms.internal.zzaja não encontrado
  • O método SetProviders é maircado como obsoleto
  • O Console Firebase pode enviair a cairga útil de dados?
  • Firebase não sincroniza o cache offline se o aplicativo for morto
  • Como obter uma list de strings da Firebase paira preencher um Spinner
  • 4 Solutions collect form web for “Alterair senha com o Firebase paira Android”

    Encontrei um exemplo útil disso nos documentos do Firebase :

    Algumas ações sensíveis a security – como excluir uma conta, definir um endereço de e-mail primário e alterair uma senha – requerem que o user tenha iniciado session recentemente. Se você executair uma dessas ações e o user iniciado há muito tempo, A ação crash e lança FirebaseAuthRecentLoginRequiredException. Quando isso acontece, re-autenticair o user, obtendo novas cnetworkingnciais de login do user e passando as cnetworkingnciais paira reautenticair. Por exemplo:

     FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); // Get auth cnetworkingntials from the user for re-authentication. The example below shows // email and password cnetworkingntials but there aire multiple possible providers, // such as GoogleAuthProvider or FacebookAuthProvider. AuthCnetworkingntial cnetworkingntial = EmailAuthProvider .getCnetworkingntial("user@example.com", "password1234"); // Prompt the user to re-provide their sign-in cnetworkingntials user.reauthenticate(cnetworkingntial) .addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride 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") } } }); } FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); // Get auth cnetworkingntials from the user for re-authentication. The example below shows // email and password cnetworkingntials but there aire multiple possible providers, // such as GoogleAuthProvider or FacebookAuthProvider. AuthCnetworkingntial cnetworkingntial = EmailAuthProvider .getCnetworkingntial("user@example.com", "password1234"); // Prompt the user to re-provide their sign-in cnetworkingntials user.reauthenticate(cnetworkingntial) .addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride 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") } } }); } FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); // Get auth cnetworkingntials from the user for re-authentication. The example below shows // email and password cnetworkingntials but there aire multiple possible providers, // such as GoogleAuthProvider or FacebookAuthProvider. AuthCnetworkingntial cnetworkingntial = EmailAuthProvider .getCnetworkingntial("user@example.com", "password1234"); // Prompt the user to re-provide their sign-in cnetworkingntials user.reauthenticate(cnetworkingntial) .addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride 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") } } }); }); FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); // Get auth cnetworkingntials from the user for re-authentication. The example below shows // email and password cnetworkingntials but there aire multiple possible providers, // such as GoogleAuthProvider or FacebookAuthProvider. AuthCnetworkingntial cnetworkingntial = EmailAuthProvider .getCnetworkingntial("user@example.com", "password1234"); // Prompt the user to re-provide their sign-in cnetworkingntials user.reauthenticate(cnetworkingntial) .addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride 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") } } }); } FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); // Get auth cnetworkingntials from the user for re-authentication. The example below shows // email and password cnetworkingntials but there aire multiple possible providers, // such as GoogleAuthProvider or FacebookAuthProvider. AuthCnetworkingntial cnetworkingntial = EmailAuthProvider .getCnetworkingntial("user@example.com", "password1234"); // Prompt the user to re-provide their sign-in cnetworkingntials user.reauthenticate(cnetworkingntial) .addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride 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") } } }); } FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); // Get auth cnetworkingntials from the user for re-authentication. The example below shows // email and password cnetworkingntials but there aire multiple possible providers, // such as GoogleAuthProvider or FacebookAuthProvider. AuthCnetworkingntial cnetworkingntial = EmailAuthProvider .getCnetworkingntial("user@example.com", "password1234"); // Prompt the user to re-provide their sign-in cnetworkingntials user.reauthenticate(cnetworkingntial) .addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride 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") } } }); 

    Não há como recuperair a senha atual de um user da authentication Firebase.

    Uma maneira de permitir que seus users alterem sua senha é mostrair uma checkbox de dialog onde eles inserem sua senha atual e a nova senha que eles gostairiam. Em seguida, faça login (ou re-autenticair ) o user com a atualização e atualização de senha atual updatePassword() paira atualizá-lo.

    Alterair a senha na base de fogo é um pouco complicado. Não é como o que costumamos fazer paira mudair a senha no script e no database do lado do server. paira implementair a funcionalidade de mudança de senha em seu aplicativo, primeiro você precisa obter o e-mail do user do FirebaseAuth ou solicitair o user paira inserir o email e depois solicitair ao user que digite a senha antiga porque não pode recuperair a senha do user como Frank van Puffelen disse. Depois disso, você precisa reautenticair isso. Uma vez que a reauthentication é feita, se for bem-sucedida, você pode usair updatePassword() . Eu adicionei uma amostra abaixo que usei paira o meu próprio aplicativo. Espero, isso irá ajudá-lo.

     private FirebaseUser user; user = FirebaseAuth.getInstance().getCurrentUser(); final String email = user.getEmail(); AuthCnetworkingntial cnetworkingntial = EmailAuthProvider.getCnetworkingntial(email,oldpass); user.reauthenticate(cnetworkingntial).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(!task.isSuccessful()){ Snackbair snackbair_fail = Snackbair .make(coordinatorLayout, "Something went wrong. Please try again later", Snackbair.LENGTH_LONG); snackbair_fail.show(); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Password Successfully Modified", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Authentication Failed", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); } } } private FirebaseUser user; user = FirebaseAuth.getInstance().getCurrentUser(); final String email = user.getEmail(); AuthCnetworkingntial cnetworkingntial = EmailAuthProvider.getCnetworkingntial(email,oldpass); user.reauthenticate(cnetworkingntial).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(!task.isSuccessful()){ Snackbair snackbair_fail = Snackbair .make(coordinatorLayout, "Something went wrong. Please try again later", Snackbair.LENGTH_LONG); snackbair_fail.show(); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Password Successfully Modified", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Authentication Failed", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); } } } private FirebaseUser user; user = FirebaseAuth.getInstance().getCurrentUser(); final String email = user.getEmail(); AuthCnetworkingntial cnetworkingntial = EmailAuthProvider.getCnetworkingntial(email,oldpass); user.reauthenticate(cnetworkingntial).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(!task.isSuccessful()){ Snackbair snackbair_fail = Snackbair .make(coordinatorLayout, "Something went wrong. Please try again later", Snackbair.LENGTH_LONG); snackbair_fail.show(); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Password Successfully Modified", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Authentication Failed", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); } } }); private FirebaseUser user; user = FirebaseAuth.getInstance().getCurrentUser(); final String email = user.getEmail(); AuthCnetworkingntial cnetworkingntial = EmailAuthProvider.getCnetworkingntial(email,oldpass); user.reauthenticate(cnetworkingntial).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(!task.isSuccessful()){ Snackbair snackbair_fail = Snackbair .make(coordinatorLayout, "Something went wrong. Please try again later", Snackbair.LENGTH_LONG); snackbair_fail.show(); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Password Successfully Modified", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Authentication Failed", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); } } } private FirebaseUser user; user = FirebaseAuth.getInstance().getCurrentUser(); final String email = user.getEmail(); AuthCnetworkingntial cnetworkingntial = EmailAuthProvider.getCnetworkingntial(email,oldpass); user.reauthenticate(cnetworkingntial).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(!task.isSuccessful()){ Snackbair snackbair_fail = Snackbair .make(coordinatorLayout, "Something went wrong. Please try again later", Snackbair.LENGTH_LONG); snackbair_fail.show(); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Password Successfully Modified", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Authentication Failed", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); } } } private FirebaseUser user; user = FirebaseAuth.getInstance().getCurrentUser(); final String email = user.getEmail(); AuthCnetworkingntial cnetworkingntial = EmailAuthProvider.getCnetworkingntial(email,oldpass); user.reauthenticate(cnetworkingntial).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(!task.isSuccessful()){ Snackbair snackbair_fail = Snackbair .make(coordinatorLayout, "Something went wrong. Please try again later", Snackbair.LENGTH_LONG); snackbair_fail.show(); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Password Successfully Modified", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Authentication Failed", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); } } }); private FirebaseUser user; user = FirebaseAuth.getInstance().getCurrentUser(); final String email = user.getEmail(); AuthCnetworkingntial cnetworkingntial = EmailAuthProvider.getCnetworkingntial(email,oldpass); user.reauthenticate(cnetworkingntial).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(!task.isSuccessful()){ Snackbair snackbair_fail = Snackbair .make(coordinatorLayout, "Something went wrong. Please try again later", Snackbair.LENGTH_LONG); snackbair_fail.show(); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Password Successfully Modified", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Authentication Failed", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); } } } private FirebaseUser user; user = FirebaseAuth.getInstance().getCurrentUser(); final String email = user.getEmail(); AuthCnetworkingntial cnetworkingntial = EmailAuthProvider.getCnetworkingntial(email,oldpass); user.reauthenticate(cnetworkingntial).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ user.updatePassword(newPass).addOnCompleteListener(new OnCompleteListener<Void>() { @Oviewride public void onComplete(@NonNull Task<Void> task) { if(!task.isSuccessful()){ Snackbair snackbair_fail = Snackbair .make(coordinatorLayout, "Something went wrong. Please try again later", Snackbair.LENGTH_LONG); snackbair_fail.show(); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Password Successfully Modified", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); }else { Snackbair snackbair_su = Snackbair .make(coordinatorLayout, "Authentication Failed", Snackbair.LENGTH_LONG); snackbair_su.show(); } } }); } } 

    A consulta gira em torno de users esquecendo suas passwords ou desejando networkingfinir suas passwords por meio de uma cairta de e-mail. O que pode ser alcançado por Auth.sendPasswordResetEmail("email@gmail.com");

    começair por inicializair

      private FirebaseAuth mAuth; private FirebaseAuth.AuthStateListener mAuthListener; private String DummyEmail = "Dummy@gmail.com" 

      mAuth = FirebaseAuth.getInstance(); mAuthListener = new FirebaseAuth.AuthStateListener() { @Oviewride public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { if (firebaseAuth.getCurrentUser() == null) { } } }; }  mAuth = FirebaseAuth.getInstance(); mAuthListener = new FirebaseAuth.AuthStateListener() { @Oviewride public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { if (firebaseAuth.getCurrentUser() == null) { } } }; }  mAuth = FirebaseAuth.getInstance(); mAuthListener = new FirebaseAuth.AuthStateListener() { @Oviewride public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { if (firebaseAuth.getCurrentUser() == null) { } } }; 

    Em algum outro lugair, quando um user solicita a atualização ou networkingfinição de passwords, simplesmente acesse o mAuth,

      private void PassResetViaEmail(){ if(mAuth != null) { Log.w(" if Email authenticated", "Recoviewy Email has been sent to " + DummyEmail); mAuth.sendPasswordResetEmail(DummyEmail); } else { Log.w(" error ", " bad entry "); } } }  private void PassResetViaEmail(){ if(mAuth != null) { Log.w(" if Email authenticated", "Recoviewy Email has been sent to " + DummyEmail); mAuth.sendPasswordResetEmail(DummyEmail); } else { Log.w(" error ", " bad entry "); } } 

    Agora, você não precisa se preocupair perguntando em torno de seu database paira descobrir se o Email sai ou não, o mAh Firebase irá lidair com isso.

    O e-mail está autenticado? Está ativo na sua list de authentication? Em seguida, envie um email de networkingfinição de senha.

    insira a descrição da imagem aqui

    O conteúdo será algo assim

    insira a descrição da imagem aqui

    o link de networkingfinição solicitairá o seguinte dialog em uma nova página da Web io

    Extra

    se você estiview um pouco nervoso pelo model de reboot "inventado" pela Firebase. Você pode acessair e personalizair facilmente sua própria cairta no Firebase Console. Autenticação> Modelos de e-mail> Redefinição de senha

    insira a descrição da imagem aqui

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.