登录验证始终失败

时间:2015-01-16 09:05:18

标签: php authentication laravel login

我正在进行PHP Laravel身份验证。注册和电子邮件激活似乎运作良好。但是当登录时,它总是返回false。我不知道这个。我的电子邮件,密码和活动列在我的数据库中似乎是正确的。

用户模式

class User extends Eloquent implements UserInterface, RemindableInterface {
protected $fillable = array('email', 'username', 'password', 'password_temp', 'code', 'active');

use UserTrait, RemindableTrait;

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

}

的login.php

<form action="{{ URL::route('login-post')}}" method="post"> 
                    <!--/ sign in title-->

                    <!--text field-->
                    <div class="form-group"> 
                        <input type="email" name="email" placeholder="Email" class="form-control rounded input-lg text-center no-border" {{ (Input::old('email') ? ' value="'.Input::old('email') . '"' : '') }}> 
                        @if($errors->has('email'))
                            {{ $errors->first('email') }}
                        @endif
                    </div> 
                    <div class="form-group"> 
                        <input type="password" name="password" placeholder="Password" class="form-control rounded input-lg text-center no-border" {{ (Input::old('password') ? ' value="'.Input::old('password') . '"' : '') }}> 
                        @if($errors->has('password'))
                            {{ $errors->first('password') }}
                        @endif
                    </div> 
                    <!--/ text field-->

                    <div class="text-center m-t m-b">
                        <input type="checkbox" name="remember" id="remember">
                        <label for="remember">
                            Remember Me
                        </label>
                    </div>

                    <input type="submit" value="Sign in" class="btn btn-lg btn-warning lt b-white b-2x btn-block btn-rounded"></input>
                    {{ Form::token() }}
                </form>

控制器

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

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

        $remember = (Input::has('remember')) ? true : false;

        //Attempt user sign-in
        $auth = Auth::attempt(array(
            'email' => Input::get('email'),
            'password' => Input::get('password'),
            'active' => 1
        ), $remember);

        if ($auth) {
            //Redirect to the intended page
            return Redirect::intended('home');
        }else {
            return Redirect::route('login')
                    ->with('global','Email/Password is wrong or account is not activated.'.Hash::make(Input::get('password')));
        }
    }

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

问题 它总是返回错误的密码。

解决方案 Laravel的数据库密码长度必须至少为60。

1 个答案:

答案 0 :(得分:0)

我认为有两个原因(同时可能有一个或两个原因)

ONE :当您存储密码时,您没有对其进行哈希Hash::make()

TWO :您在设置通行证后修改了config/app.php [key]

相关问题