問題描述
所以,我要為我的網站切換到 Laravel.我的舊網站目前擁有大約 500 個用戶.每個用戶都有一個附加到他們的 md5 哈希,作為密碼(廢話^^).
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 時,我希望使用 Auth::attempt不幸的是,它使用自己的方法來散列密碼字符串.我不希望我的所有用戶都更改他們的密碼,因為我要切換到 Laravel,是否可以讓 Auth 類使用 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? :)
如果是,有人可以告訴我怎么做嗎?
If yes, can someone show me how?
推薦答案
MD5 已經過時了.我建議你不要試圖保留它.相反,當用戶第一次登錄并且 Auth::attempt
失敗時,您應該嘗試將他們的密碼與數據庫作為 MD5 進行比較
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 Auth - 使用 md5 而不是集成的 Hash::make()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!