When trying to use Laravel’s Auth class, I see that it always fails because (AFAIK) the attempt() method is only trying to select the username:
string(55) "SELECT * FROM `mdl_user` WHERE (`username` = ?) LIMIT 1"
(That’s outputted via Event::listen(‘laravel.eloquent’))
I’m using Eloquent as the driver, the table fields are ‘username’ and ‘password’, and my model (Moodle_User, located at models/moodle/user.php) is written like this:
class Moodle_User extends Eloquent {
public static $table = 'user';
public static $connection = 'moodle';
}
If I use the model as-is, it works flawlessly:
// returns the correct object
$user = Moodle_User::where('username', $username)->where('password', md5($password))->get();
Also, I’m not using the Hash class because Moodle currently uses MD5, so I call Auth::attempt() like this:
Auth::attempt(array('username' => $username, 'password' => md5($password)))
But it always returns false. If I do the exact same thing via the Moodle_User model, it works as expected.
Why does it ALWAYS return false?
You’re suppose to use
Hash::make()notmd5()to hash your passwords.http://laravel.asia/p/laravel-authentication
I’d suggest you use your own driver because
attemptin theeloquentdriver andfluentdriver usesHash::check():https://github.com/laravel/laravel/blob/master/laravel/auth/drivers/eloquent.php#L53
https://github.com/laravel/laravel/blob/master/laravel/auth/drivers/fluent.php#L41