This is useful for anybody who is running Laravel Framework, but for some reason keep their User logic in Wordpress.
Note: This assumes any other Wordpress to Laravel migrations have already been taken care of (like adding remember_token to user table and setting up a User-model that extneds Illuminate\Contracts\Auth\Authenticatable)
requires either MikeMcLin\WpPassword or Hautelook\Phpass
PS. This can probably also be accomplished by swapping out the app-hasher for the entire project!
All that is needed is to
- extend the User Provider in Laravel
- modify the config to use the new provider
- register the new provider in the AuthServiceProvider
- edit (or extend the functionality) everywhere where 'email'/'username' should be 'user_email' and 'password' should be 'user_pass'
Create a Class WPuserProvider as app/Extensions/WPUserProvider.php and extend Illuminate\Auth\EloquentUserProvider
use Illuminate\Auth\EloquentUserProvider;
use Hautelook\Phpass\PasswordHash;
class WPUserProvider extends EloquentUserProvider {
Override the method validateCredentials
public function validateCredentials(Authenticatable $user, array $credentials){
$plain = $credentials['user_pass'];
$hasher = new PasswordHash(8, true); // same settings as WP
return $hasher->check($plain, $user->user_pass);
}
open and edit config/auth.php
'defaults' => [
'guard' => 'wpguard',
'passwords' => 'users'
],
...
'guards' => [
'wpguard' => [
'driver' => 'session',
'provider' => 'wpusers'
],
...
...
'providers' => [
'wpusers' => [
'driver' => 'wpdriver',
'model' => App\User::class
],
...
...
Open and edit App\Providers\AuthServiceProvider.php in method boot() add the following
Auth::provider('wpdriver', function ($app, array $config) {
return new WPUserProvider($app['hash'], $config['model']);
});
Find in all necessary files (most of them probably listed below) where Laravel's 'email' and 'password' attributes are listed and replace them with 'user_email' and 'user_pass'
- Illuminate\Auth\EloquentUserProvider
- Illuminate\Contracts\Auth\UserProvider
- Illuminate\Contracts\Auth\Authenticatable
- Illuminate\Auth\SessionGuard
- Illuminate\Contracts\Auth\Guard
- App\Http\Middleware\RedirectIfAuthenticated
- App\Http\Controllers\Auth\LoginController
- Illuminate\Foundation\Auth\AuthenticatesUsers
- resources\views\auth*.*