2016-02-17 84 views
0

我试图获取用户的密码,当我做电子邮件/密码验证...获取密码?

但是,当我做getAuth()/ onAuth()..对象只是电子邮件,uid,令牌,等等,但不是密码。

我需要密码的原因是因为我想能够更改用户密码。要做到这一点,您需要将用户旧密码作为angularfire文档状态的语法:

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com"); 
ref.changePassword({ 
    email  : "[email protected]", 
    oldPassword : "correcthorsebatterystaple", 
    newPassword : "neatsupersecurenewpassword" 
}, function(error) { 
    if (error === null) { 
    console.log("Password changed successfully"); 
    } else { 
    console.log("Error changing password:", error); 
    } 
}); 

Thankyou。

+1

如果您已正确设计您的应用程序,那么知道用户密码的唯一方法就是询问他们。你有一个表格,用户可以提供旧密码和新密码吗? – tadman

+0

任何服务都可以访问用户的实际密码是一种极其糟糕的做法。通常服务提供商会保存用户密码生成的密钥并进行保存。 因此,如上所述,您需要询问用户旧的*和*新密码以允许更改。 – idan

+0

Firebase知道旧密码,所以你只需要询问用户并将输入传递给'changePassword'。您不需要知道旧密码,因为Firebase确实会检查自己 – mjr

回答

0

您可以将密码存储在firebase数据库中。我不会推荐你,因为你会被攻击。但我会建议提示用户输入旧密码。并检查它是否写入。然后找到更改用户密码。正如代码所解释的那样(添加Sweet-Alert使其成为优先:)):

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com"); 

ref.onAuth(function(authData) { 

    swal({ 
     title: "Old Password!", 
     text: "Write Old Password", 
     type: "input", 
     showCancelButton: true, 
     closeOnConfirm: false, 
     animation: "slide-from-top", 
     inputPlaceholder: "OldPassword..." 
    }, function(inputValue) { 
     if (inputValue === false) return false; 
     if (inputValue === "") { 
      swal.showInputError("You need to write something!"); 
      return false 
     } 
     $scope.originalPassword = inputValue 


     swal({ 
      title: "New Password!", 
      text: "Write New Password", 
      type: "input", 
      showCancelButton: true, 
      closeOnConfirm: false, 
      animation: "slide-from-top", 
      inputPlaceholder: "NewPassword..." 
     }, function(inputValue) { 
      if (inputValue === false) return false; 
      if (inputValue === "") { 
       swal.showInputError("You need to write something!"); 
       return false 
      } 
      $scope.NewPassword = inputValue 

      ref.changePassword({ 
       email: authData.password.email, 
       oldPassword: $scope.originalPassword, 
       newPassword: $scope.NewPassword 
      }, function(error) { 
       if (error === null) { 
        swal("Nice!", "Password Changed Succesfully!", "success"); 
       } 
       else { 
        sweetAlert("Oops...", "Error Changing Password" + error, "error"); 
       } 
      }); 



     }); 




     swal("Nice!", "You wrote: " + inputValue, "success"); 
    }); 


})