Search code examples
phplaraveldrupal

Log in to a drupal 7 website with laravel


I've been trying to create a laravel login with users from a drupal 7 database. Since drupal 7 has his own encription method for passwords, the ones that come with laravel don't work, hence whenever there's a try to log in it always returns authentication failure.

    {

        $request->validate([
            'mail' => 'required|string|email',
            'pass' => 'required|string',
            'remember_me' => 'boolean',
        ]);
        //dd(hash('sha256',$request->pass));
        $credentials = request(['mail', 'pass']);
        if (!Auth::attempt(['mail' =>$request->mail, 'pass' => hash('sha256',$request->pass)])) {
            return response()->json([
                'message' => 'Unauthorized'], 401);
        }
        $user = $request->user();
        
        $tokenResult = $user->createToken('Personal Access Token');

        $token = $tokenResult->token;

        if ($request->remember_me) {
            $token->expires_at = Carbon::now()->addWeeks(1);
        }

        $token->save();

        $user->api_token = $tokenResult->accessToken;

        return response()->json($user);
    } 

This is my login method in the controller.

I don't have access at all to the drupal project.

I'm open for any idea.


Solution

  • If you navigate to includes/password.inc in your drupal directory, you will find a function named: user_check_password. This method can help you verify your plain text password against the hashed password.

    So, the easiest way would be connecting laravel to the existing drupal database and make use of the password.inc file from drupal.