我正在尝试将用户从Wordpress导入Laravel,但我无法正确获取密码。当用户登录时,我需要针对md5检查密码并在bcrypt中将其哈希,如果它是正确的。
我在AuthenticatesUsers.php login()
中尝试了这个//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)
使用mikemclin/laravel-wp-password来检查/检查您的密码:
$password = 'plain-text-password';
$wp_hashed_password = '$P$B7TRc6vrwCfjgKLZLgmN.dmPo6msZR.';
if ( WpPassword::check($password, $wp_hashed_password) ) {
// Password success!
} else {
// Password failed :(
}