2013-05-29 23 views
0

骨干模型,这里是我的登录模式保存响应值这使得保存()调用

LoginModel = Backbone.Model.extend({ 
      initialize: function(){ 

      }, 
      defaults:{ 
       userName: 'undefined', 
       passwd: 'undefined' 

      }, 
      urlRoot: 'https://www.xxxx.xxxx/encryptedcredentials', 
      parse: function(response, options){ 


      }, 
      validate: function(attributes, options){ 

      } 

     }); 

我张贴令牌服务器接收加密的用户名密码&。在成功的方法,它返回加密的凭据。

// creating a loginmodel 

var loginmodel = new LoginModel(); 


// calling save to post the token 

loginmodel.save({token:"xxxxxxxxxxxxxx"},{ 
    success: function(model, response){ 

    //server is returning encrypted the user name and password 
     response.encUserName; 
     response.encPassword 

    }, 
    error: function(model, response){ 
    } 
); 

如何设置响应(userName,passwd)到用户创建的loginmodel的属性?

+1

难道你不会只使用'model.set'吗?还是你说你需要解密用户名和密码? – freejosh

回答

0

您的服务器不应该能够为您提供用户的密码。干净利落。如果它可以那么你的用户的数据是而不是安全。

当服务允许您使用用户名/密码登录时,服务器不应该以您或其他任何人可以检索纯文本版本的原始密码的方式存储密码。您应该将密码存储为用户输入的哈希值。然后,当他们尝试登录时,您对输入执行相同的加密,并检查它是否与您存储在数据库中的加密哈希匹配。这就是为什么当您在网站(Twitter,Facebook,Google)上忘记密码时,唯一的选择是重置密码。

你应该从来没有能够找回纯文本版本的密码。 永远。

+0

谢谢idebehold。我赞同你。在这里我正在寻找,如何将凭证保存在loginmodel对象的用户名和密码属性中。 – yokks