3

So I was working with a Laravel application and something went wrong, so I wanted to charge an early backup version of it. The application is from the company I'm currently working for and I was surprised the employees before me didn't have any git repositories or anything, so I had to literally copy an old project. Now I have a problem with the login part: it simply doesn't work.

Once I enter the username and password, nothing happens and the page refresh. I've already comprobed that the database (with the users) exists and is working correctly via commands. It's important to say that the project is entirely hosted on a Vagrant VM which I connect via WinSCP.

I suspect there's a problem with the login-database connection part, but I don't know what it is. I'm kind of a newbie here.

Btw, the app is the intranet of the company. I didn't ruin the original but the developer version, anyways I need to fix it and I'm a little desperate.

Here's the .env file. Instead of the pass, i'll put "password" bc company.

/*DELETED FOR COMPANY ISSUES*/

The /config/database.php file:

/*DELETED FOR COMPANY ISSUES*/

The login.blade.php file:

/*DELETED FOR COMPANY ISSUES*/

And a part of the web.php file, the file used for routes:

Route::get('/', function () {
    return redirect('admin');
});
Route::group( ['middleware' => ['prevent-back']], function() {

    Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
    Route::post('login', 'Auth\LoginController@login');
    Route::get('logout', 'Auth\LoginController@logout')->name('logout');

    Route::get('admin', 'AdminController@index')->name('admin');
});


Route::group( ['middleware' => ['auth','prevent-back']], function() {

    Route::post('admin/changeuser/{user}', 'AdminController@changeLoggedUser')->name('admin.changeuser');    

    Route::post('notification/readall','NotificationController@doReadAll');    
    Route::get('notification/unread','NotificationController@getUnread');
    Route::post('notification/{notification}/read','NotificationController@doRead');    

EDIT: I've found some more info that (maybe?) could be useful. I screenshoted the info Laravel told me via browser.

enter image description here

enter image description here


EDIT2: Following the instructions I discovered that my ADLDAP server is not working properly. Once I try to composer require adldap2/adldap2-laravel it tries to install but says this:

enter image description here

I also tried to use Tinker to search for the users and stuff. I can see the users using App/Models/User:all(); but it won't work if I try something like this:

enter image description here

Apparently the bind doesn't work. I'm not very familiarized with it but here's the fragment of code that is not working:

public function bind($username, $password, $sasl = false)
{
    if ($this->isUsingTLS()) {
        $this->startTLS();
    }

    if ($sasl) {
        return $this->bound = ldap_sasl_bind($this->getConnection(), null, null, 'GSSAPI');
    }

    return $this->bound = ldap_bind($this->getConnection(), $username, $password);
}
1

I'm suspecting you are using laravel 6, currently Adldap2 isn't fully supported in laravel 6, try using lower version e.g version 5.7 supports the installation of Adlap2.

If that's not the case then navigate to config directory then open auth.php scroll to providers and ensure the active driver is either eloquent or database and not ldap

 'providers' => [
    'users' => [
        //REMOVE THIS 'driver' => 'ldap',
        'driver' => 'eloquent',
        'model' => App\User::class,
        'table' => 'users',
    ],
| improve this answer | |
0

"Once I enter the username and password, nothing happens and the page refresh" sounds like a redirect loop.

Verify that all of your redirects are correct

  • check out your LoginController

it might have the following property

protected $redirectTo = '/';

make sure it is redirected to the correct url

  • in the following lines in yourweb.php

    Route::get('/', function () {
        return redirect('admin');
    });
    

try not to redirect('admin'), but just echo some text to verify that everything executed before this step works

  • you might as well have a problem answered here

Regarding your update.

It seems that your Laravel installation uses Adldap2/Adldap2-Laravel.

  • Do you have LDAP server installed?
  • Are privileged users (used for Laravel authentication) added to LDAP server?
  • Are you able to query ldap server from terminal successfully?
  • try to query LDAP server from Laravel as described here

For example, change the following commands accordingly:

    // Finding a user:
    $user = Adldap::search()->users()->find('john doe');

    // Searching for a user:
    $search = Adldap::search()->where('cn', '=', 'John Doe')->get();

and see if this gives you an error OR $user contains NULL OR $user contains expected result.


UPDATE 2

Are you sure that Authentication in your Laravel application is done through the MySQL DB and not through LDAP server?

When you run App/Models/User:all(); - you connect through the MySQL DB, but in your "EDIT:" the error says "Can't contact LDAP server".

In Laravel it is possible to authenticate admin account either through MySQL or LDAP (among many other methods). Your Laravel installation currently tries to make authentication not through MySQL, but through LDAP server. It seems that LDAP server does NOT exist.

Test, if you have LDAP server by trying to connect to it from command line (not from Laravel). How to test a LDAP connection from a client Then, check if it has an admin user added on that server.

Otherwise, if you are 100% sure that your Laravel admin account authentication is done through the MySQL DB (the admin account with its password is stored there), you have to remove adldap2/adldap2-laravel package from Laravel and configure Laravel not to use LDAP authentication.

Important! Be sure to use git or some other version control system just not to make things even worse!

If you are not 100% sure whether Laravel auth is done through MySQL or LDAP, I would not remove adldap2/adldap2-laravel package, because presumably somebody added it to Laravel installation before you and your current Laravel setup is trying to authenticate through LDAP. So first try to connect to LDAP server by logging in to Vagrant and trying to connect to it from the command line. How to test a LDAP connection from a client OR Simple way to check ldap (AD) is running OR using telnet as in this comment

| improve this answer | |
  • I tried everything you said and nothing worked. I think that it's not a problem o redirecting but connection with the database. My LoginController : protected $redirectTo = '/admin'; Also, the echo you suggested in the web.php doesn't work. I think we came upon something here. – Coexito May 13 '19 at 8:10
  • verify: 1) LDAP server installation, 2) LDAP server authentication, 3) Laravel configuration for LDAP server, 4) query to LDAP returns expected result – Dmytro Dzyubak May 13 '19 at 19:43
  • thank you for your help, I think we could be approaching the issue. I updated the post with more info. – Coexito May 14 '19 at 11:07
  • answer updated. – Dmytro Dzyubak May 14 '19 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.