4

I have a existing project in php. I am moving project from core to laravel. but I am getting problem to implement the admin authentication from existing table. As I did much research on that and I found that there are some commands to create authentication functionality automatically.

Please some one help me to create authentication process manually using laravel model and from exist table table.

tereško
  • 58,060
  • 25
  • 98
  • 150
AMit SiNgh
  • 325
  • 4
  • 17

1 Answers1

0

I think you can do this steps:

  1. Modify your existing table for Laravel authentication by changing or adding this columns:

    • username (string)
    • password (string)
    • created_at (datetime)
    • updated_at (datetime)
    • remember_token (string)
  2. Change existing passwords to Bcrypt hash type that is the default hashing method in Laravel or read some guide like this to force Laravel work in your existing hashing function.

  3. Make Laravel User model. You can do it like any tutorial with Laravel Migration. It must be like this:

    <?php namespace App;
    
    use Illuminate\Auth\Authenticatable;
    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Auth\Passwords\CanResetPassword;
    use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
    use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
    
    class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
    
        use Authenticatable, CanResetPassword;
    
        protected $table = 'users';
    
        protected $fillable = ['password', 'username', 'email'];
    
        protected $hidden = ['password', 'remember_token'];
    }
    
  4. Read Laravel Authentication class guide. It's easy, for example you can check if user is login or not with Auth::check() function, or try to login like this :

    if (Auth::attempt(['email' => $email, 'password' => $password])) {
        // Authentication passed...
    }
    
Community
  • 1
  • 1
Mahmood Kohansal
  • 1,021
  • 2
  • 16
  • 42