2016-02-19 105 views
0

我目前正在從Firebase關注此Email & Password Authentication tutorial保護密碼客戶端Firebase

這裏是電子郵件和密碼登錄的基本代碼:

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com"); 
ref.authWithPassword({ 
    email : "[email protected]", 
    password : "correcthorsebatterystaple" 
}, function(error, authData) { 
    if (error) { 
    console.log("Login Failed!", error); 
    } else { 
    console.log("Authenticated successfully with payload:", authData); 
    } 
}); 

對於每一頁我通過我的網站上瀏覽,我需要用電子郵件地址和密碼憑據訪問重新認證數據庫?

如果是這樣,我怎麼通過emailpassword通過網頁,而不會使密碼容易暴露。

我對安全性很陌生,不想遇到任何安全問題或數據泄露,因此我依賴於第三方服務。

+0

我的回答有幫助嗎? –

回答

2

火力地堡仍然存在的認證狀態在瀏覽器中,當你撥打:

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com"); 
ref.authWithPassword({ 
    email : "[email protected]", 
    password : "correcthorsebatterystaple" 
}, function(error, authData) { 
    if (error) { 
    console.error("Login Failed!", error); 
    } 
}); 

要檢索的頁面重新加載持久性驗證狀態,您可以使用onAuth()方法:

// this will fire even if not authenticated and authData 
// will be null 
ref.onAuth(function(authData) { 
    if (authData) { 
    console.log(authData.uid); 
    } 
}); 

據隨着安全性的提高,Firebase需要HTTPS連接,因此所有電子郵件和密碼都將通過網絡加密。