【问题标题】:set a new password to a user in Meteor在 Meteor 中为用户设置新密码
【发布时间】:2015-02-27 23:54:40
【问题描述】:

这就是我想要做的, 当用户链接一个社交帐户时,然后创建用户,但我希望让用户提交密码,以允许他在没有他的电子邮件和密码的情况下登录。

我创建了一个表单让用户提交他的密码,但我找不到正确的方法,唯一可用的方法是

Accounts.changePassword(currentPassword, newPassword, function(error) {
        if (error) {
            message = 'There was an issue: ' + error.reason;
        } else {
            message = 'You reset your password!'
        }
    });

这种方法的问题是我不知道用户的当前密码,他还没有密码但用户仍然存在,当我调用 Meteor.user() 时。

有什么建议吗?

【问题讨论】:

标签: meteor


【解决方案1】:

您可以轻松地执行以下操作。

  if (Meteor.isServer) {
  Meteor.startup(function () {
    Accounts.setPassword("theUserId", "theNewPassword")
  });
}

或使用meteor.methods(未经测试的代码)

 //server
 Meteor.methods({
      changePAssword:function(userId.newPassword){
        Accounts.setPassword(userId, newPassword)
      }
    })

    //client
    Meteor.call('changePAssword',this.userId,newPasswordVariable,function(err,result){
          if(!err){
           console.log("Congrats you change the password")
          }else{
            console.log("pup there is an error caused by " + err.reason)
          }
        })

【讨论】:

  • 嗨@ethaan。在这种情况下,新密码不是通过 DDP 以明文形式传输到服务器的吗?
  • 更合适的可能是password: { digest: SHA256( password ), algorithm: 'sha-256'}
  • 谢谢@ethaan。在这种情况下,我有一个基本问题。一旦服务器接收到这个结构 {digest: "", algorithm: "sha-256'},Accounts.setPassword 函数如何使用它?可以直接作为密码参数传递,或者如何检索原始密码字符串?
  • Meteor 默认是安全的,如果你使用 https 字符串将是安全的,所以问题可能不是“你如何通过网络传递它”而是“你如何存储在db" 这就是摘要到位的地方
猜你喜欢
  • 1970-01-01
  • 2018-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-15
  • 1970-01-01
  • 2017-09-08
相关资源
最近更新 更多