无论我做什么都不会使Laravel 4认证工作。这是我在routes.php文件中的代码。
Route::post('check', function() {
$check = Hash::check(Input::get('password'), Hash::make('titanic1'));
var_dump($check);
var_dump(Input::all());
$auth = Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password')));
var_dump($auth);
});
正如您所看到的,Hash :: check返回true但Auth :: try返回false。仅供参考,我使用Hash :: make(Input :: get('password'))将散列密码存储在数据库中。此外,我已确认用于存储密码的字段长度为60个字符。而且,我正在实现UserInterface及其方法。
我正在使用Ardent库进行输入验证。这是我的用户模型。
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
use LaravelBook\Ardent\Ardent;
use Zizaco\Entrust\HasRole;
class User extends Ardent implements UserInterface, RemindableInterface {
use HasRole;
protected $table = 'users';
protected $fillable = array('email','username','password','password_confirmation');
protected $guarded = array('id');
protected $hidden = array('password');
public $autoHydrateEntityFromInput = true;
public $autoPurgeRedundantAttributes = true;
public static $passwordAttributes = array('password');
public $autoHashPasswordAttributes = true;
public static $rules = array(
'email' => 'required|email|unique:users',
'username' => 'required|alpha_dash|unique:users',
'password' => 'required|alpha_num|min:8|confirmed',
'password_confirmation' => 'required|alpha_num|min:8'
);
public function getAuthIdentifier()
{
return $this->getKey();
}
public function getAuthPassword()
{
return $this->password;
}
public function getReminderEmail()
{
return $this->email;
}
public function beforeSave()
{
if ($this->isDirty('password')){
$this->password = Hash::make($this->password);
}
return true;
}
}
非常感谢任何帮助。感谢。
乌尼。