Laravel Auth - 使用 md5 而不是集成的 Hash::make()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19878319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Auth - use md5 instead of the integrated Hash::make()
提问by Jazerix
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 ^^).
所以,我正在为我的网站切换到 laravel。我的旧网站目前拥有大约 500 个用户。每个用户都有一个附加到他们的 md5 哈希,作为密码(废话^^)。
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? :)
当我切换到 Laravel 时,我希望使用 Auth::attempt 不幸的是它使用自己的方法来散列密码字符串。我不希望我的所有用户都更改他们的密码,因为我要切换到 Laravel,是否可以让 Auth 类使用 md5,这样我的用户就不必切换密码了?:)
If yes, can someone show me how?
如果是的话,有人可以告诉我怎么做吗?
回答by Someguy123
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
MD5 已经过时了。我建议你不要试图保留它。相反,当用户第一次登录并Auth::attempt
失败时,您应该尝试将他们的密码与数据库作为 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'));
}
}