Laravel&流星密码哈希 [英] Laravel & Meteor password hashing

查看:215
本文介绍了Laravel&流星密码哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个应用程序,一个用于Laravel 5.2,一个用于Meteor。我想收集与两个平台兼容的密码哈希。

数据库单独存储散列值




  • 密码为Laravel。

  • meteor_password 流星。


    这两个平台默认使用bcrypt,默认10轮,但Meteor在bcrypt之前似乎是纯密码。



    如果Meteor创建密码哈希 abc ,我可以使用普通密码,并将其与 abc 使用Laravel的内部,即 Auth :: attempt()

      $ sha256 = hash('sha256',$ request-> get('password'),false); 

    这有效。然而,如果我在Laravel中注册一个新用户,并存储散列 meteor_password ,在对流星中的散列进行身份验证时,它会失败并显示错误消息禁止登录。 此错误似乎意味着不正确的凭据。



    我创建哈希的方式与我在Laravel中验证时一样。

      $ meteor_password = bcrypt(hash('sha256',$ plain,false)); 

    看起来很奇怪,它会以单向而非其他方式工作,所以我认为我失踪在2011年,PHP的BCrypt实现中发现了一个错误,所以它们 security.stackexchange.com/a/108789/88377\">已将原始 2a 版本指标更改为 2x 2y ,这是今天使用的,表示密码已被固定版本散列。

    因此,

    ,由PHP的 2y 生成的哈希应该与节点的 2a 生成的哈希相同。



    为了正确处理NPM模块(由Meteor使用),应该更改前缀,因为它不确认 2y

      $ meteor_password = bcrypt(hash('sha 256',$ plain,false)); 
    //替换它使用类似于:
    $ meteor_password = str_replace('$ 2y','$ 2a',$ meteor_password);
    //或
    $ meteor_password [2] ='a';


    I have two applications, one in Laravel 5.2 and one in Meteor. I want to collect hashes for passwords which are compatible with both platforms.

    The database stores the hashes separately

    • password for Laravel.
    • meteor_password for Meteor.

    Both platforms use bcrypt with 10 rounds by default, but Meteor appears to sha256 the plain password before bcrypt.

    If Meteor creates password hash abc, I can sha256 the plain password, and compare it with abc using Laravel's internals, i.e. Auth::attempt()

    $sha256 = hash('sha256', $request->get('password'), false);
    

    This works. Laravel successfully authenticates the user.

    However, if I register a new user in Laravel, and store the hash meteor_password, when authenticating against that hash in Meteor, it fails with the error message "Login Forbidden". This error appears to be mean incorrect credentials.

    I'm creating the hash in the same way as I did when I verified it in Laravel.

    $meteor_password = bcrypt(hash('sha256', $plain, false));
    

    It seems strange that it'd work one way and not the other so I assume I'm missing something.

    解决方案

    In 2011, a bug was discovered in PHP's BCrypt implementation, so they changed the original 2a version indicator to 2x and 2y, which is used today, to indicate that the password was hashed by the fixed version.

    Therefore, the hash generated by PHP's 2y should be identical to the one generated by node's 2a.

    The prefix should be changed in order to be correctly processed by the NPM module (used by Meteor), as it does not acknowledge 2y.

    $meteor_password = bcrypt(hash('sha256', $plain, false));
    // replace it useing something like:
    $meteor_password = str_replace('$2y', '$2a', $meteor_password);
    // or
    $meteor_password[2] = 'a';
    

    这篇关于Laravel&流星密码哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆