【问题标题】:Laravel Auth returning falseLaravel Auth 返回 false
【发布时间】:2015-03-17 03:13:32
【问题描述】:

我正在使用内置 Auth::attempt 功能的 Laravel 来尝试为我的网站创建登录脚本。但是,Auth::attempt 总是返回 false。这个问题似乎与许多其他有类似问题的人相似,但是他们收到的答案对我的问题没有帮助/适用。我在 YouTube 上关注 Phpacademy 的教程,我的登录几乎是逐字记录的。 Laravel 是否修改了 Auth::attempt 现在的工作方式?任何帮助,将不胜感激。下面是我在 AccountController.php 中的登录功能

public function postLogin() {

    $validator = Validator::make(Input::all(),
        array(
            'email' => 'required|email',
            'password' => 'required'    
        )
    );

    if($validator->fails()) {
        return Redirect::route('account-login')
                            ->withErrors($validator)
                            ->withInput();
    }

    else {

        $auth = Auth::attempt(array(
            'email' => Input::get('email'),
            'password' => Input::get('password'),
            'active' => 1
        ));

        if($auth) {
            Redirect::intended('/');
        }

        else {
            return Redirect::route('account-login')
                        ->with('global',"Email/password wrong");
        }

    }

    return Redirect::route('account-login')
                        ->with('global',"There was a problem signing you in.");
}

模型/User.php

<?php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    use UserTrait, RemindableTrait;

    //fillable for the database
    protected $fillable = array('email','password','first-name','last-name','username','city','state','password','password_temp','code','active');

    /**
     * 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', 'remember_token');

    }

?>

【问题讨论】:

  • 是的,我认为 Laravel 已经更改了一些安全设置,因为该 phpacademy 教程已经完成。凭记忆,只是一个简单的小东西,和 CSRF 保护什么的有关。您能否发布此文件的代码:app/models/User.php
  • @MichaelColeman 添加了它

标签: php authentication laravel laravel-4


【解决方案1】:

我不确定它是否会影响你,因为你似乎没有使用“记住我”功能,但是 Laravel 在 4.1.2 版本中引入了以下安全功能。
这是对我们中的许多人在遵循 phpacademy auth 教程后运行以使 auth 工作所需的问题/修复的解释。 希望它有所帮助。

http://laravel.com/docs/4.2/upgrade#upgrade-4.1.26

【讨论】:

    猜你喜欢
    • 2017-05-11
    • 2019-06-28
    • 2018-01-07
    • 2019-05-24
    • 2015-03-03
    • 2014-11-22
    • 2017-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多