【发布时间】:2015-02-18 18:31:51
【问题描述】:
我正在学习 Laravel 4,但现在我无法让用户登录我的应用程序。 我阅读了多个教程来创建登录区域,但我无法创建会话。
解决方案: laravel 4 custom named password column
您必须小心“密码”索引,无论您的表如何命名密码字段,它必须是 Auth::attempt 函数中的“密码”
用户数据库表:
- idusuario, int(11)
- 登录,varchar(45)
- 名词,varchar(45)
- 对比,varchar(255)
- 状态,布尔值
- remember_token, varchar(100)
- idperfil, int(11)
这是我的认证功能:
Route::post('login', function()
{
if(Auth::attempt([ 'login' => Input::get('login'), 'contrasena' => Input::get('password') ]))
return Redirect::intended('home');
return Redirect::to('login')->with('response','Ingreso invalido');
}
我的自定义用户模型:
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class Usuario extends Eloquent implements UserInterface, RemindableInterface {
protected $table = 'usuario';
protected $hidden = array('contrasena');
protected $fillable = array('login', 'nombre', 'status', 'idperfil');
protected $guarded = array('idusuario', 'contrasena');
public $primaryKey = 'idusuario';
public $timestamps = false;
public function getAuthIdentifier()
{
return $this->login;
}
public function getAuthPassword()
{
return $this->contrasena;
}
public function getRememberToken()
{
return $this->remember_token;
}
public function setRememberToken($value)
{
$this->remember_token = $value;
}
public function getRememberTokenName()
{
return 'remember_token';
}
public function getReminderEmail()
{
return false;
}
我的看法:
{{ Form::open(array('url' => 'login', 'role' => 'form')) }}
<div class="response">{{ $response or '' }}</div>
<div class="form-group">
<label for="login">Usuario</label>
<input type="text" class="form-control" id="login" name="login" placeholder="Ingrese su login">
</div>
<div class="form-group">
<label for="password">Contraseña</label>
<input type="password" class="form-control" id="password" name="password" placeholder="*********">
</div>
<button type="submit" class="btn btn-primary">Iniciar Sesión</button>
</form>
我一直在测试
dd(Auth::attempt([ 'login' => Input::get('login'), 'contrasena' => Input::get('password') ]));
但我无法修复它,但是当我测试哈希检查以验证密码时,它返回 true! 有什么想法吗? 提前致谢!
【问题讨论】:
-
我在发布之前找到并测试了该发布解决方案,但它不起作用
-
这是伙计,请确保您所做的与链接答案中的完全相同。否则粘贴您尝试过的代码。
标签: session authentication laravel login login-attempts