将Wordpress密码传输到Laravel

时间:2016-12-01 20:12:20

标签: php wordpress laravel laravel-5.2

我正在尝试将用户从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密码。

1 个答案:

答案 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 :(
}