【问题标题】:Securing password client side Firebase保护密码客户端 Firebase
【发布时间】:2016-02-19 16:09:16
【问题描述】:

我目前正在关注来自 Firebase 的 Email & Password Authentication tutorial

这是使用电子邮件和密码登录的基本代码:

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

对于我在网站上浏览的每个页面,我是否需要使用电子邮件和密码凭据重新进行身份验证才能访问数据库?

如果是这样,我如何通过网页传递emailpassword 而不会使密码容易暴露。

我对安全非常陌生,不想遇到任何安全问题或数据泄漏,因此我依赖第三方服务。

【问题讨论】:

    标签: javascript html security authentication firebase


    【解决方案1】:

    当您调用时,Firebase 会在浏览器中保持身份验证状态:

    var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
    ref.authWithPassword({
      email    : "bobtony@firebase.com",
      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 连接,因此所有电子邮件和密码都通过网络进行加密。

    【讨论】:

      猜你喜欢
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-19
      • 2012-09-03
      • 2015-04-14
      • 1970-01-01
      • 2017-06-29
      相关资源
      最近更新 更多