【发布时间】:2014-06-20 14:14:53
【问题描述】:
我一直在到处搜索,但无法弄清楚为什么我的 Auth::attempt() 一直失败。请帮帮我。
这是我的表格:
<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>
这是我的登录功能:
$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!";
我的 User.php 是默认的。看起来像这样:
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;
}
}
这就是我保存新用户信息的方式(使用 Eloquent):
$user = new User();
$user->username = Input::get('username');
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->save();
但是当用户使用正确的凭据登录时,我一直失败。现在已经为此工作了几天,不禁觉得我错过了一些微不足道的东西。请帮忙?谢谢!
【问题讨论】:
-
您在数据库中的密码字段是否至少有 60 个字符长?
-
@AntonioCarlosRibeiro 是的,它有 64 个字符长
标签: php authentication laravel laravel-4