Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Meteor-如何使用服务器端密码验证_Javascript_Meteor - Fatal编程技术网

Javascript Meteor-如何使用服务器端密码验证

Javascript Meteor-如何使用服务器端密码验证,javascript,meteor,Javascript,Meteor,我正在“Accounts.onCreateUser”函数中执行服务器端验证,以便也可以传递options对象。我不知道如何使用validate user函数来实现这一点 首先,如果我走错了方向,我完全愿意接受正确的答案,所以请给出建议。 我不知道如何在服务器端验证密码长度。是因为它在创建之前已经转换了吗?测试时,如果我输入一个字符作为密码,它不会抛出错误 Accounts.onCreateUser(function (options, user) { if (options.profil

我正在“Accounts.onCreateUser”函数中执行服务器端验证,以便也可以传递options对象。我不知道如何使用validate user函数来实现这一点

首先,如果我走错了方向,我完全愿意接受正确的答案,所以请给出建议。 我不知道如何在服务器端验证密码长度。是因为它在创建之前已经转换了吗?测试时,如果我输入一个字符作为密码,它不会抛出错误

Accounts.onCreateUser(function (options, user) {
    if (options.profile) {
        user.profile = options.profile;
        user.profile.user_status = "new user";
    }

    // Error checking
    var errors = "";
    if (user.username.length === 0) {
        errors = errors + '<li>Email is required</li>';
    }
    if (user.username.length !== 0 && user.username.length < 4) {
        errors = errors + '<li>Email too short</li>';
    }

    if (user.profile.firstname.length === 0) {
        errors = errors + '<li>First name is required</li>';
    }

    if (user.profile.firstname.length !== 0 && user.profile.firstname.length < 2) {
        errors = errors + '<li>First name is too short</li>';
    }

    if (user.profile.lastname.length === 0) {
        errors = errors + '<li>Last name is required</li>';
    }
    if (user.profile.lastname.length !== 0 && user.profile.lastname.length < 2) {
        errors = errors + '<li>Last name is too short</li>';
    }

    if (user.services.password.length === 0) {
      errors = errors + '<li>Please enter a password</li>';
    }

    if (user.services.password.length < 7) {
      errors = errors + '<li>Password requires 7 or more characters</li>';
    }

    if (errors) {
      throw new Meteor.Error(403, errors);
    } else {
      return user;
    }

});
Accounts.onCreateUser(函数(选项,用户){
if(options.profile){
user.profile=options.profile;
user.profile.user\u status=“新用户”;
}
//错误检查
var误差=”;
if(user.username.length==0){
错误=错误+“
  • 需要电子邮件”
  • ; } if(user.username.length!==0&&user.username.length<4){ 错误=错误+“
  • 电子邮件太短”
  • ; } if(user.profile.firstname.length==0){ errors=errors+'
  • 需要名字
  • '; } if(user.profile.firstname.length!==0&&user.profile.firstname.length<2){ errors=errors+'
  • 名字太短了; } if(user.profile.lastname.length==0){ errors=errors+'
  • 姓氏为必填项
  • '; } if(user.profile.lastname.length!==0&&user.profile.lastname.length<2){ errors=errors+'
  • 姓氏太短; } if(user.services.password.length==0){ errors=errors+'
  • 请输入密码; } if(user.services.password.length<7){ errors=errors+'
  • 密码需要7个或更多字符; } 如果(错误){ 抛出新的流星。错误(403,错误); }否则{ 返回用户; } });
  • 我没有使用帐户用户界面。试着推出我自己的。。。对于Meteor来说,这是一场全新的战斗,试图理解帐户的创建和验证。如果有一种方法可以通过ValidateNewUser函数实现这一点,那么我应该改用它吗

    感谢您的帮助。

    根据,密码“不是通过网络以明文发送的”,因此您在服务器端查看的密码字符串与用户键入的密码字符串不同

    编辑:至少,我是这么想的

    EDIT2:在中找到了一条评论,证实了这一点。

    帐户密码使用,这有点复杂,所以我在这里不详细描述。对散列令牌的实际检查发生在基本上,密码不会以纯文本字符串的形式到达服务器,因此在使用SRP时,您将无法在服务器上强制执行密码策略

    另外值得注意的是,对于那些(可以理解)不想自己实现SRP的人,有一个仅DDP的“纯文本”登录选项。如广告所示,仅当用户连接到w/时才应使用。我可能会从那里开始

    同时,您至少可以执行一些客户端强制操作,直到可以滚动服务器端登录处理程序为止


    您可能还想查看这个自定义登录处理程序教程。

    我已经找到了执行此操作的最佳方式。希望这能帮助别人

    我在服务器端使用一种方法来验证并返回错误(如果有)。然后继续创建帐户

    Meteor.call('Validate_Registration', email, password, cpassword, firstname, lastname, terms, function(error) {
                if (error) {
                    error = error.reason;
                    $('#Error-Block').fadeIn().children('ul').html(error);
                    console.log(error);
                } else {
                    Accounts.createUser({
                        username: email,
                        email: email,
                        password: password,
                        profile: {
                            firstname: firstname,
                            lastname: lastname
                        }
                    }, function(error) {
                        if (error) {
                            error = error.reason;
                            $('#Error-Block').fadeIn().children('ul').html(error);
                        } else {
                            var uid = Accounts.connection.userId();
                            Meteor.call('Verify_Email', uid, email);
                            Router.go('/email-instructions');
                        }
                    });
                }
            });
    
    在这一点上,我唯一不确定的是它是否正确使用:

    var uid = Accounts.connection.userId();
    

    这似乎只是当前用户的本地存储,并存储在用户的本地存储中

    你没有使用任何预制的东西?不是帐户密码包?我使用的是帐户库和帐户密码。嗨,佩佩!你睡得不多,是吗?我不应该说预先构建的东西,因为这是误导。编辑我的问题。:)您知道如何在服务器端验证密码吗?只是有个想法。。。也许我应该在调用Accounts.createUser…@user1447679之前验证用户在客户端写入的密码在发送到服务器之前总是经过哈希处理(在客户端)。您无法在服务器上验证它;你最好的办法是在客户端验证它(尽管坏人可能会忽略你在客户端的验证规则)。即使我使用自己的表单?1.将表单值发送到服务器验证逻辑。2.如果通过,则调用Accounts.CreateUser函数?@user1447679 Yea,这对您很有用。我的错误是只考虑使用流星提供给你的东西。但我只需要在客户端验证密码;普通用户不知道如何愚弄您的验证过程,知道的用户也不会愚蠢到这样做:P@user1447679,Meteor不通过明文发送密码的原因是因为它不安全。绕开这件事不是很聪明,他们这样做是有原因的。正如Peppe指出的,如果有人绕过你的验证,那真的是他们的损失!我无法理解这一点。这只是增加了额外的流量来执行检查。坏用户仍然可以忽略检查结果,就像他们可以忽略客户端检查一样。