2017-09-16 111 views
1

我有一個場景,需要在用戶執行不可逆轉的任務之前,根據用戶的Firebase密碼檢查輸入的密碼。這與創建帳戶或登錄不同。您如何檢查Firebase密碼?它看起來不像firebase.auth().currentUser中的password財產。Firebase - 檢查密碼

更新: 用戶必須驗證他們的密碼,刪除按鈕將運行一個函數來檢查它。如果它與Firebase密碼相符,則「刪除」按鈕將成功觸發漂亮模式彈出。

Password Verification

+2

這聽起來像你正在尋找[重新認證用戶的憑證](https://firebase.google.com/docs/auth/web/manage-users#re-authenticate_a_user)。 –

回答

0

我建議你來存儲用戶密碼的地方,如果你需要對證在一些點。

而不是將它存儲在您的數據庫內(這將不安全)我會親自將它存儲在用戶的設備上使用UserDefaults,以便您可以輕鬆地訪問它,只要您需要執行您的明智任務。

更新:

另一種可能性是使用reauthenticateWithCredential方法。如果方法返回成功,那麼執行你的敏感任務。如果失敗,請讓用戶輸入正確的密碼。

按照您的要求,這是你將如何使用自己的電子郵件&密碼重新認證用戶:

// First you get your current user using Auth : 

let currentUser = Auth.auth()?.currentUser 

// Then you build up your credential using the current user's current email and password : 

let credential = EmailAuthProvider.credential(withEmail: email, password: password)  

// use the reauthenticate method using the credential : 
currentUser?.reauthenticate(with: credential, completion: { (error) in 

    guard error == nil else { 
     return 
    } 

    // If there is no error, you're good to go 

    // ...Do something interesting here 

}) 

您可以找到火力地堡文檔這裏裏面的一些更多的解釋:https://firebase.google.com/docs/auth/ios/manage-users

+0

您能否提供一個'reauthenticateWithCredential'的例子。它需要傳遞一個'憑證'參數,我不知道如何使用。 – FiringBlanks

+0

當然,我會更新我的答案! – Alex