Laravel 4 Auth:尝试不起作用 [英] Laravel 4 Auth:attempt not working

查看:61
本文介绍了Laravel 4 Auth:尝试不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难使用Laravel 4 Auth :: attempt方法,遵循正确的文档,阅读了几个SO线程,但仍然无法正常工作.

I am having hard time working with Laravel 4 Auth::attempt method , followed the right documentation, read couple of SO threads but still i am not able to get it working.

$userData = array('email' => 'admin@admin.com','password' => 'admin');
if(Auth::attempt($userData)){
    // redirect
}
else{
   echo 'Invalid';
}

并且每次都返回Invalid

And it returns Invalid everytime

现在我不确定真正的原因是什么.

Now i am not sure what is the actual reason.

在我的config/auth.php中,我有以下内容

In my config/auth.php i have following

<?php

   return array(
/*
|--------------------------------------------------------------------------
| Default Authentication Driver
|--------------------------------------------------------------------------
|
| This option controls the authentication driver that will be utilized.
| This drivers manages the retrieval and authentication of the users
| attempting to get access to protected areas of your application.
|
| Supported: "database", "eloquent"
|
*/

'driver' => 'eloquent',

/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/

'model' => 'User',

/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/

'table' => 'users',

/*
|--------------------------------------------------------------------------
| Password Reminder Settings
|--------------------------------------------------------------------------
|
| Here you may set the settings for password reminders, including a view
| that should be used as your password reminder e-mail. You will also
| be able to set the name of the table that holds the reset tokens.
|
*/
'reminder' => array(
    'email' => 'emails.auth.reminder', 'table' => 'password_reminders',
),
 );
 ?>

推荐答案

请确保您数据库中的密码字段具有64个字符的空间. varchar(64)

Make sure that your password field in your db has space for 64 characters. varchar(64)

散列需要64个字符,并且如果您在插入时将散列密码截断(因此永远无法肯定地验证密码),您就不会从laravel中收到错误消息.

The hash needs 64 characters and you won't get an error from laravel if your hashed password is truncated on insertion (and therefore not able to ever validate a password positively).

这篇关于Laravel 4 Auth:尝试不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆