Laravel 4 Auth - 使用md5代替集成的Hash :: make() [英] Laravel 4 Auth - use md5 instead of the integrated Hash::make()

查看:110
本文介绍了Laravel 4 Auth - 使用md5代替集成的Hash :: make()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在切换到我的网站laravel。我的旧网站目前拥有约500名用户。每个用户都有一个md5哈希值作为密码(duh ^^)。

当我切换到laravel时,我希望使用Auth :: attempt
,不幸的是它使用自己的方法来哈希密码字符串。我不希望所有用户都更改密码,因为我正在切换到laravel,是否可以使Auth类使用md5,因此我的用户不必切换密码? :)



如果是的话,有人可以告诉我如何?

解决方案

MD5是可怕的过时。我建议你不要试图保留它。
相反,当用户首次登录时, Auth :: attempt 失败,您应该尝试将其密码与数据库比较为MD5


$ b $

  $ user = User :: where('username','=',Input :: get('username')) - > first (); 

if(isset($ user)){
if($ user-> password == md5(Input :: get('password'))){//如果他们的密码仍然是MD5
$ user-> password = Hash :: make(Input :: get('password')); //转换为新格式
$ user-> save();
Auth :: login(Input :: get('username'));
}
}


So, I'm switching over to laravel for my site. My old site currently holds around 500 users. Each user has a md5 hash attached to them, as the password (duh ^^).

As I'm switching over to laravel, I wish to use the Auth::attempt unfortunately it uses its own method to hash password strings. I don't want all my users to change their password, because I'm switching to laravel, is it possible to make the Auth class use md5 instead, so my users don't have to switch password? :)

If yes, can someone show me how?

解决方案

MD5 is horribly outdated. I recommend that you don't try to keep it. Instead, when a user first logs in, and Auth::attempt fails, you should then try to compare their password to the database as MD5

$user = User::where('username', '=', Input::get('username'))->first();

if(isset($user)) {
    if($user->password == md5(Input::get('password'))) { // If their password is still MD5
        $user->password = Hash::make(Input::get('password')); // Convert to new format
        $user->save();
        Auth::login(Input::get('username'));
    }
}

这篇关于Laravel 4 Auth - 使用md5代替集成的Hash :: make()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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