1

I have a form and I'm trying to login by using Laravels Auth method.

At the moment I have this snippet:

$input = Input::all();

$login = Auth::attempt([
'username' => $input['username'],
'password' => $input['password']
]);

if($login){
return "Logged in";
}

dd('problem');

But even after entering correct credentials I'm getting to see "problem"

in models/User.php I've changed my table name to tbl_login(like I have in the DB) and that is the only change I've made in it

and in my login model I have

class Login extends Eloquent {
protected $guarded = array();
protected $table = "tbl_login";
protected $primaryKey = "pk_loginID";

public static $rules = array();
}

I also checked this topic but didn't really help and I'm hoping that you guys can help me with this now.

Just as info and a sidenote: table name in Db = tbl_login

primary key field is pk_loginID

username field = username

password field = password

Did I forget something or did I do something wrong?

EDIT:

I've found the problem more specific, but not a solution for it. My password field in the DB has another name than the default password field that Laravel uses. How can I say to Laravel to use my custom password field?

4

2 回答 2

1

I've found the solution

In the User model in the method getAuthPassword()

public function getAuthPassword()
{
     return $this->attributes['passwordFieldinYourTable'];//change the 'passwordFieldinYourTable' with the name of your field in the table
}

That's it :)

于 2013-10-08T08:19:46.393 回答
0

您无法更改它,但您可能可以通过在密码字段中创建新的修改器来解决此问题:

<?php

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

class User extends Eloquent implements UserInterface, RemindableInterface {

    ...

    public function getPasswordAttribute()
    {
        return $this->YourPasswordField;
    }

    public function setPasswordAttribute($password)
    {
        $this->YourPasswordField = $password;
    }


}
于 2013-10-05T12:11:34.193 回答