2016-02-17 87 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"); 
    }); 


})