【问题标题】:Migration from CI Ion Auth to Laravel authentication从 CI Ion Auth 迁移到 Laravel 身份验证
【发布时间】:2014-06-26 12:08:16
【问题描述】:

我必须将一个项目从 CI 迁移到 Laravel。该项目使用 Ben Edmunds (http://benedmunds.com/ion_auth/) 的 Ion Auth。问题是是否有可能保留旧用户密码(因此旧用户不必恢复他们的密码)。在 Ion Auth 的配置文件中设置了 sha1 作为哈希方法

$config['hash_method']    = 'sha1';

【问题讨论】:

    标签: php codeigniter authentication laravel ion-auth


    【解决方案1】:

    你应该做的是这样的事情(半伪代码 - 未经测试 - 但你明白了):

       login()
       {
            $password = Input::get('password');
            $user = User::where('email', '=', Input::get('email');
    
            if (sha1($password) == $user->password)
            {
                  // User old password matches - so now lets re-hash the password as bcrypt
                  $user->password = Hash::make($password);
            }
    
            ... do rest of authentication normally
        }
    

    基本上在您进行正常的 Laravel 登录之前,请检查 sha1() 旧密码是否匹配,如果匹配,则将原始密码转换为 Laravel 使用的 bcrypt 哈希。

    这允许您在不重置任何密码的情况下迁移用户。

    【讨论】:

    • 奇妙的隐形迁移!
    【解决方案2】:

    由于 Ion Auth 不使用直接的 sha1 哈希,因此这将无法正常工作。您可以查看模型以查看哈希算法,然后您只想在 Laravel 中复制它。

    要查找的主要内容是检查您的配置,看看您使用的是 SHA1 还是 BCrypt,因为 Ion Auth 支持两者。

    【讨论】:

      猜你喜欢
      • 2021-08-26
      • 2017-03-18
      • 2012-06-04
      • 2011-06-07
      • 2018-02-15
      • 1970-01-01
      • 2013-01-14
      • 2015-01-02
      • 2021-09-27
      相关资源
      最近更新 更多