Laravel Auth::attempt( ) failing


Laravel Auth::attempt( ) failing

我正在使用Laravel 4的登录系统。我可以成功地register用户,但当我尝试使用详细信息-电子邮件和密码login时,每次都失败,我不知道为什么。

这是dbusers表的Schema:

Schema::create('users', function($table){ 
            $table->increments('id'); 
            $table->string('fname', 255); 
            $table->string('lname', 255); 
            $table->string('email')->unique(); 
            $table->string('password',128); 
            $table->string('remember_token', 100);
            $table->timestamps(); 
        }); 

这是我的Login Form:

<form action="{{action('HomeController@handleLogin')}}" method="post">
        <div class="form-group">
            <label for="email">Email</label>
            <input type="text" class="form-control" name="email"/>
        </div>
        <div class="form-group">
            <label for="password">Password</label>
            <input type="password" class="form-control" name="password"/>
        </div>
        <input type="submit" value="Login" class="btn btn-primary"/>
    </form>

这是我的Login ActionHomeController:

public function handleLogin() {
        $rules = array(
            'email'    => 'required', 
            'password' => 'required'
        );
        $credentials = array(
            'email' => Input::get('email'),
            'password' => Input::get('password')
        );
        $validator = Validator::make($credentials, $rules);
        if($validator->passes()){
            echo "Validation passed";
            if(Auth::attempt($credentials)){
                echo "Logged In";die();
            }else{
                echo "Logged Failed";die();
            }
        }else{
            echo "Validation failed";die();
        }
    }

我不明白为什么会失败,即使我硬编码电子邮件和密码进入$credentials数组,它也不会登录。

任何帮助都是非常感激的。

注册代码

public function handleRegister(){
        //Validation Rules
        $rules = array(
            'fname'=>'required|alpha|min:2',
            'lname'=>'required|alpha|min:2',
            'email'=>'required|email|unique:users',
            'password'=>'required|alpha_num|between:6,12|confirmed',
            'password_confirmation'=>'required|alpha_num|between:6,12'
        );
        //Validator
        $validator = Validator::make(Input::all(), $rules);
        if($validator->passes()){//PASS
            //Save user to DB
            $user = new User;
            $user->fname = Input::get('fname');
            $user->lname = Input::get('lname');
            $user->email = Input::get('email');
            $user->password = Hash::make(Input::get('password'));
            $user->save();
            return Redirect::action('HomeController@getLogin')->with('message', 'Thanks for registering!');
        }else{//FAIL
            //Display Errors
            return Redirect::action('HomeController@getRegister')->with('message', 'The following errors occured')->withErrors($validator)->withInput();
        }
    }

Database row

id  type    fname   lname   email   password    school  address_1   address_2   address_3   address_4   remember_token  created_at  updated_at
7   'N  Jack    Coldrick    jackcoldrick@yahoo.com  $2y$10$nRdbkOeEyOB4NLiphGEb5u2Qvcs2Xwu/x7zIcxq3mY3TQWCkiE6a6    'N  'N  'N  'N  'N      2014-08-18 14:01:22 2014-08-18 14:01:22

尝试手动登录

public function handleLogin() {
        $rules = array(
            'email'    => 'required', 
            'password' => 'required'
        );
        $credentials = array(
            'email' => Input::get('email'),
            'password' => Input::get('password')
        );
        $validator = Validator::make($credentials, $rules);
        if($validator->passes()){
            echo "Validation passed";
            $user = User::where('email', $credentials['email'])
            ->andWhere('password', Hash::make($credentials['email']))
            ->first();
            if(null !== $user && Auth::login($user)){
                echo "Logged In";die();
            }else{
                echo "Logged Failed";die();
            }
        }else{
            echo "Validation failed";die();
        }
    }