2016-12-01 24 views
0

我試着從Wordpress向Laravel導入用戶,但我無法獲得正確的密碼。當用戶登錄時,我需要檢查密碼對md5並散列在bcrypt中,如果它是正確的。轉移WordPress的密碼Laravel

我在AuthenticatesUsers.php登錄()

//If user got here it means the AUTH was unsuccessful 
//Try to log them IN using MD5 
if($user = User::where('email', $credentials['email'])->where('password', md5($credentials['password']))->first()){ 
    //It this condition is true, the user had the right password. 

    //encrypt the password using bcrypt 
    $user->password = Hash::make($credentials['password']); 
    $user->save(); 

    if (Auth::guard($this->getGuard())->attempt($credentials, $request->has('remember'))) { 
     return $this->handleUserWasAuthenticated($request, $throttles); 
    } 

    return $this->handleUserWasAuthenticated($request, $throttles); 

} 

我也試圖與Migrating old md5 passwords to bcrypt with Laravel 5.2's built in auth試過,但我不能得到它來驗證MD5密碼。

+0

在'$用戶,會發生什麼=用戶::在哪裏(...'確實找到用戶 –

+0

是,它發現用戶,但它不能驗證MD5密碼 – mattesj

+0

如果它找到用戶,MD5密碼已經驗證,你無法做的是驗證你的用戶密碼後bcrypt密碼,我認爲...問題可能在'if(Auth :: guard($ this-> getGuard()) - >嘗試($ credentials,$ request-> has('remember')))' –

回答

0

使用mikemclin/laravel-wp-password到了/校驗H您的密碼:

$password = 'plain-text-password'; 

$wp_hashed_password = '$P$B7TRc6vrwCfjgKLZLgmN.dmPo6msZR.'; 

if (WpPassword::check($password, $wp_hashed_password)) { 
    // Password success! 
} else { 
    // Password failed :(
}