I've been searching everywhere, but cannot figure out why my Auth::attempt() keeps failing. Please help me out.
This is my form:
<h2>Admin Login</h2>
<form method="post" action="<?php echo url('login-process') ?>">
Username: <input type="text" name="username" /> <br/>
Password: <input type="password" name="password" />
<button type="submit">Login</button>
</form>
This is my login function:
$username = Input::get('username');
$password = Input::get('password');
if (Auth::attempt(array('username' => $username, 'password' => $password))) {
echo "success!"; //just for testing purposes
} else {
echo "fail!";
My User.php is the default one. looks like this:
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password');
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->password;
}
/**
* Get the e-mail address where password reminders are sent.
*
* @return string
*/
public function getReminderEmail()
{
return $this->email;
}
}
And this is how I save the new user information (using Eloquent):
$user = new User();
$user->username = Input::get('username');
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->save();
But I keep getting fail when user logs in with correct credentials. Been working on this for a few days now, and can't help but feel that I'm missing something trivial. Lend a hand please? Thanks!