Hi there I am new to laravel and I am trying to code functionality of my login form here are the codes:
this is how I create new user (works well)
public
Check to make sure that your database password field is 60 characters.
To all laravel 4 developers who are facing the Auth::attempt() login failure with valid creditials!
Solution:
In Model add method:
public function setPasswordAttribute($pass) {
$this->attributes['password'] = Hash::make($pass);
}
In UserController:
//Create User or Register
public function postCreate() {
$input = Input::all();
$user = new User;
$user->username = Input::get('username');
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user = User::create($input);
return Redirect::action("Frontend\HomeController@index");
}
//Login or Sign in
public function postSignin() {
$userdata = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
if (Auth::attempt($userdata, true)) {
Session::put('username', Auth::user()->username);
return Redirect::action("Frontend\HomeController@index");
} else {
return Redirect::action("Frontend\UserController@getLogin")
->with('message', 'Your username/password combination was incorrect')
->withInput();
}
Hope i have helped someone out there
Fool me!
Although I have checked it many times, I could not see the line 'username' => 'email',
in auth config file.
it should be 'username' => 'username',
since I am going to use username for login.