Reputation: 7
I've installed Laravel 4.2 but ran into a problem where the 'Auth::attempt()' function is not willing to let the user in but I can log in with the 'Auth::loginUsingId()' function.
My User model
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
public $timestamps = false;
protected $table = 'user';
protected $primaryKey = 'user_id';
protected $hidden = array('user_pass', 'remember_token');
public function getAuthIdentifier(){
return $this->getKey();
}
public function getAuthPassword(){
return $this->user_pass;
}
public function getRememberToken(){
return $this->user_remembertoken;
}
public function setRememberToken($value){
$this->user_remembertoken = $value;
}
public function getRememberTokenName(){
return "user_remembertoken";
}
public function getReminderEmail(){
return $this->user_email;
}
}
My routes (I've put in some exaple)
Route::get('login', function(){
$user = 'dd';
$pass = '123456';
$credentials =["user_nickname" => "dd","user_pass" => "123456"];
if(Auth::attempt($credentials)){
echo 'Login Successful';
}
else{
echo 'Login Failed';
}
});
Route::get('check', function()
{
if(Auth::check()){echo 'identified';}
else{echo 'not identified';}
return;
});
Route::get('reg', function()
{
$user = new User;
$user->user_nickname = 'dd';
$user->user_pass = Hash::make('123456');
$user->user_realname = 'dd';
$user->user_email = '[email protected]';
$user->user_accesslevel = 1;
$user->user_language = 'HU';
$user->save();
});
Route::get('forcelogin', function()
{
Auth::loginUsingId(6,TRUE);
return;
});
My Database
user_id | smaillint
user_nickname | varchar(25)
user_pass | char(60)
user_email | varchar(255)
user_realname | varchar(60)
user_accesslevel | tinyint(3)
user_language | char(2)
user_regdate | timestamp
user_remembertoken | char(60)
Upvotes: 0
Views: 310
Reputation: 60048
The user password column MUST BE 'password'. This is hard coded into Laravel and is not configurable (even with the getAuthPassword()
function).
So change your database migration from
user_pass | char(60)
to
password | varchar(60)
and change
$user->user_pass = Hash::make('123456');
to
$user->password = Hash::make('123456');
when registering the user and it will work.
Upvotes: 1
Reputation: 734
Change user password column field from char(60) to "varchar 255" delete user password hash recreate it and give it a try!
Upvotes: 0