Php 为什么Auth::trunt方法总是返回false?
我正在尝试进行基本身份验证,当我尝试对用户进行身份验证时,但是Php 为什么Auth::trunt方法总是返回false?,php,authentication,laravel,laravel-4,Php,Authentication,Laravel,Laravel 4,我正在尝试进行基本身份验证,当我尝试对用户进行身份验证时,但是Auth::trunt方法返回false 刀片 {{ Form::open(array('url' => 'usuario')) }} <input type="text" class="text" id="email" name="email" placeholder="Correo" {{(Input::old('email')) ? 'value ="'. Input::ol
Auth::trunt
方法返回false
刀片
{{ Form::open(array('url' => 'usuario')) }}
<input type="text" class="text" id="email" name="email" placeholder="Correo" {{(Input::old('email')) ? 'value ="'. Input::old('email').'"' : '' }}>
<p>{{ $errors->first('email') }}</p>
<input type="text" class="text" id="password" name="password" placeholder="Contraseña" >
<p>{{ $errors->first('password') }}</p>
{{ Form::submit('Ingresar', array('class' => 'bg1')) }}
{{ Form::close() }}
Auth
'driver' => 'database',
'model' => 'Usuario',
'table' => 'Usuario',
型号
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class Usuario extends Eloquent implements UserInterface, RemindableInterface{
protected $table = 'Usuario';
protected $primaryKey = 'idUsuario';
protected $hidden = array('Contrasena');
protected $fillable = array(
'Nombre',
'Apellido',
'Tipo',
'password',
'email',
'Fono',
'Foto'
);
}
代码总是返回false并将我重定向到登录,当数据库使用不正确的数据时有很多原因会导致每次返回false: 1) 您的密码未正确存储/散列,您必须使用以下内容对其进行散列:
Hash::make($password);
这是一种通过Laravel正确散列创建用户和存储密码的方法:
$user = new User;
$user->email = 'example@domain.com';
$user->password = Hash::make('thePasswordToBeHashed');
$user->save();
2) 您的密码列大小没有足够的空间来存储哈希密码。它的长度必须至少为60字节,但迁移时使用:
$table->string('password');
dd(Input::all());
这是一个很好的实践,因为如果这个尺寸在将来发生变化,你就不会有问题
3) 您没有试图登录的电子邮件(Correo)用户。仔细检查一下,因为这比我们想象的要频繁。您还可以尝试手动执行此操作,以查看它是否真的有效:
$userdata = array(
'Correo' => 'youremail@domain.com',
'Password' => 'password'
);
dd( Auth::attempt($userdata) );
4) 您的表单未正确传递数据,请通过以下方式检查表单是否确实有效:
$table->string('password');
dd(Input::all());
并检查您是否获得了正确的数据
5) 你有一个验证,所以问题可能就在上面。添加另一条骰子消息以确保:
if($validator->fails())
{
dd('Validation is failing!');
...
}
6) 从评论中可以看出:
$userData = array('email' => Input::get('email'), 'password' => Input::get('password'));
return (string) Auth::attempt($userData));
7) 尝试手动创建其他用户:
$user = new User;
$user->email = 'example@domain.com';
$user->password = Hash::make('passwordExample');
$user->save();
并使用它登录:
$userData = array('email' => 'example@domain.com', 'password' => 'passwordExample');
return (string) Auth::attempt($userData));
1.我改变了,你什么都没发生。2.我的应用程序中不使用迁移,密码大小为1003。我在模型和数据库中修复了它,但什么也没发生。4.我接收到正确的输入。5.验证不会失败。所以在3中。你还是一无所获(假)?如果3不起作用,就什么都不起作用。
userData=array('email'=>Input::get('email'),'password'=>Hash::make(Input::get('password'));return Auth::trunt($userData)
show….响应内容必须是实现_-toString()、给定“boolean”的字符串或对象。
必须将其强制转换为字符串。您不需要散列来尝试,只需要存储在数据库中。已编辑以显示如何操作。您的数据库中仍然存在问题。检查密码是否真的被哈希了。请向我们展示您的用户创建控制器方法。