6

I have a form with 2 fields (username, password) and a mysql table with those 2 same fields (username, password), and I authentication system working properly :)

But, I can not make it work if my table fields have different names, for example: (my_user, my_pass).

If you just change the username field on the other also works for me, that gives me problems is the password field.

My config auth.php

'driver' => 'eloquent'

Update

Already found the solution in my controller, the password name can not change.

Before (WRONG): What I've done in first place was wrong

$userdata = array(
        'my_user' => Input::get('my_user'),
        'my_pass' => Input::get('my_pass')
    );

it should be

$userdata = array(
        'my_user' => Input::get('my_user'),
        'password' => Input::get('my_pass')
    );
giannis christofakis
  • 8,201
  • 4
  • 54
  • 65
Luck Nilis
  • 61
  • 1
  • 3

3 Answers3

7

You can define you own username and password field in the auth.php inside the config folder.

 return array(
    'driver' => 'eloquent',
    'username' => 'my_user',
    'password' => 'my_pass',
    'model' => 'User',
    'table' => 'users',
 );

I hope this can be of some help.

giannis christofakis
  • 8,201
  • 4
  • 54
  • 65
saran banerjee
  • 2,895
  • 1
  • 13
  • 12
3

I ran into this same problem. You need to extend your model:

// User.php

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

class User extends Eloquent implements UserInterface, RemindableInterface {

    protected $fillable = array('name','passwd','email','status','timezone','language','notify');
    protected $hidden = array('passwd');

    protected $table = "users_t";
    protected $primaryKey = "uid";

    public static $rules = array(
        'name' => 'required',
        'passwd' => 'required',
        'email' => 'required'
    );

    public function getAuthIdentifier() {
        return $this->getKey();
    }

    public function getAuthPassword() {
        return $this->passwd;
    }

    public function getReminderEmail() {
        return $this->email;
    }

    public static function validate($data) {
        return Validator::make($data,static::$rules);
    }
}
HeyBigE
  • 31
  • 1
-4

You need to implements this methods too:

public function getRememberToken(){

}
public function setRememberToken($value){

}
public function getRememberTokenName(){

}
DooBie
  • 1