简体   繁体   中英

Can't login as admin in laravel4

I have created an admin interface and created an admin table in my database with admin and password field. In first attempt, I manually created password and I made it md5 encrypted, but soon I come to know that laravel does not support md5 encrypted password.

So I decided to create hashed password and what I did is that , from my end user registration panel, I registered a new user which automatically creates a hashed password in the database, I copy that password and paste it into my admin table's password field , only then was I able to login into my admin panel.

In that time , I didn't create the logout functionality, because I was just testing, so closed my browser and came in the second day, and suddenly I can't login into my admin panel with same username and password, giving the unauthorised message "The username or password you provided is wrong!" which surprised me a lot, because with same username and password I was able to logg in my admin account the previous day. I am sure that there is something wrong in laravel or may be there is some issues in my code but can't figure it out. Here is the folder structure and my code

src/
   app/
      controllers/
                 admin/
                      AdminController.php
      model/
           admin.php
      routes.php 
      filters.php

admin.php

<?php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class \Admin extends Eloquent implements UserInterface, RemindableInterface    {



    public function getRememberToken()
    {
        return $this->remember_token;
    }

    public function setRememberToken($value)
    {
        $this->remember_token = $value;
    }

    public function getRememberTokenName()
    {
        return 'remember_token';
    }

    protected $table = 'admins';

    protected $fillable=array
    (   'username',
        'password'

    );



    use UserTrait, RemindableTrait;

AdminController.php

<?php

namespace Admin;

class AdminController extends \BaseController{

    public function AdminLogin(){
        return \View::make('admin.login');
    }

public function AdminLoginPost(){

    $auth=\Auth::attempt(array(

          'username' => \Input::get('username'),
          'password' => \Input::get('password')
            ));

    if($auth){

        return \Redirect::intended('marriage-admin');

    }else{

        return \Redirect::route('admin')->with('global','The username or password you provided is wrong!');
    }
    return \Rediret::route('admin')->with('global','Please Review Your Admin Database.');
}

}

?>

Hi in the next path

In app/
     config/
        auth.php

You can configure the Driver, Model and Table that reference when laravel create a validation.

the auth file you must add the model used for the validation laravel well as the table to which reference will do . For example in your case:

<?php

return array(

/*
|--------------------------------------------------------------------------
| Default Authentication Driver
|--------------------------------------------------------------------------
|
| This option controls the authentication driver that will be utilized.
| This driver manages the retrieval and authentication of the users
| attempting to get access to protected areas of your application.
|
| Supported: "database", "eloquent"
|
*/

'driver' => 'eloquent',

/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/

'model' => 'admin',

/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/

'table' => 'your table here',

/*
|--------------------------------------------------------------------------
| Password Reminder Settings
|--------------------------------------------------------------------------
|
| Here you may set the settings for password reminders, including a view
| that should be used as your password reminder e-mail. You will also
| be able to set the name of the table that holds the reset tokens.
|
| The "expire" time is the number of minutes that the reminder should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/

'reminder' => array(

    'email' => 'emails.auth.reminder',

    'table' => 'password_reminders',

    'expire' => 120,

),

);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM