算法可行,但一旦密碼已轉換爲散列並保存到數據庫中,它就不會重定向到主頁。相反,它會重定向到登錄頁面,說明登錄憑據不正確。但是如果我嘗試登錄,那沒關係。我究竟做錯了什麼?將md5移植到Laravel中的問題
AuthenticatesUsers.php
protected function attemptLogin(Request $request)
{
$check = $this->guard()->attempt(
$this->credentials($request), $request->has('remember')
);
if ($check === false)
{
$user = User::where('username','=',$request->input('username'))->first();
if(isset($user)) {
if($user->password == md5($request->input('password'))) { // If their password is still MD5
$hashed_password = Hash::make($request['password']); // Convert to new format
$user->password = $hashed_password;
$user->save();
return $this->guard()->attempt(
array(
'username'=>$request->input('username'),
'password'=>$hashed_password
), $request->has('remember')
);
} else {
// Redirect to the login page.
return false;
}
}
}
return $check;
}
所以你想象用戶可以使用'md5 hashed password'登錄? –
是的,因爲我將當前的MD5換成了laravel的哈希。但問題是在那之後。 – EatCodePlaySleep
所以你需要將數據庫中現有的md5密碼轉換爲'laravel hashing'?如果是這樣,試着說'if(password_verify($ request-> input('password'),$ user-> password))'而不是。 –