Laravel 4 Laravel Auth::尝试/登录页面为';我不能正常工作

Laravel 4 Laravel Auth::尝试/登录页面为';我不能正常工作,laravel-4,login,forms-authentication,Laravel 4,Login,Forms Authentication,我的注册页面工作正常。数据正确插入到名为“registered_users”的表中。我的登录页面工作不正常 routes.php <?php Route::get('/', function() { return View::make('index'); }); //About page Route::get('about', function() { return View::make('about'); }); //reister route Rou

我的注册页面工作正常。数据正确插入到名为“registered_users”的表中。我的登录页面工作不正常

routes.php

<?php



 Route::get('/', function()
{
    return View::make('index');
});


//About page
 Route::get('about', function()
{
    return View::make('about');
});

 //reister route

Route::get('register', function(){

return View::make('register');

});

Route::post('register_action', function()
{
        $obj = new RegisterController() ;
        return $obj->store();
});

Route::get('login', function(){

return View::make('login');

});


Route::post('logincheck', function(){

// username and password validation rule

    $data =  Input::except(array('_token')) ;
    $rule  =  array(
            'name'       => 'required',
            'password'   => 'required',
    ) ;
    $message = array(
       'password.required' => 'The Password field is required.',
       'name.required'      => 'The Username  is required.',
    );


    $v = Validator::make($data,$rule);





    if ($v->fails()) {

            // username or password missing

            // validation fails

            // used to retain input values

            Input::flash ();

            // return to login page with errors

            return Redirect::to('login')

            ->withInput()

            ->withErrors ($v->messages ());

    } else {

                    $userdata = array (

                    'name' => Input::get('name'),

                    'password' => Input::get('password')

                );

                //var_dump($userdata);
                If (Auth::attempt ($userdata)) {

        // authentication success, enters home page

         return Redirect::to('home');

     } else {

         // authentication fail, back to login page with errors

         return Redirect::to('login')
            ->withErrors('Incorrect login details');


         }//end if 




    }//end of v else

});


// Route::get ('home',function(){

//  return View::make('home');

// });
Route::get ('test',function(){

    return View::make('test');

    });

Route::group (array ('before' => 'auth'), function () {

    Route::get ('home',function(){

    return View::make('home');

    });

});
Route::get ('logout',function(){

Auth::logout ();

return Redirect::to('login');

});
login.blade.php

    @extends('layout')

    @section('main')
    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Registrationhhjh</title>
    </head>
    <body>

        <section class="header">
        <div class="bannner">&nbsp;</div>
        <div class="container">
            <h1>Sign In</h1>

            @if ($errors->any())

            <ul style="color:red;">

            {{ implode('', $errors->all('<li>:message</li>')) }}

            </ul>

            @endif

  {{ Form::open(array('url' => 'logincheck')) }}
             {{ Form::text('name', '', array('placeholder'=>'Name')) }}<br><br>
            {{ Form::password('password', '', array('placeholder'=>'Password')) }}<br><br>
            {{ Form::submit('Sign in', array('class'=>'btn btn-success')) }}
            <!-- {{ Form::submit('register', array('class'=>'btn btn-primary')) }} -->
            {{ HTML::link('register', 'Register', array('class' => 'btn btn-info'))}}

            {{ Form::close() }}



           </div>

        </section>





    </body>
    </html>

    @stop
@extends('layout'))
@节(“主节”)
注册hhjh
登录
@如果($errors->any())
    {{内爆(''.$errors->all('
  • :message
  • )}
@恩迪夫 {{Form::open(数组('url'=>'logincheck'))} {{Form::text('name','',数组('placeholder'=>'name'))}

{{Form::password('password','',数组('placeholder'=>'password'))}

{{Form::submit('Sign-in',array('class'=>'btn-btn-success'))} {{HTML::link('register','register',array('class'=>'btn btn info'))} {{Form::close()}} @停止
php(model)。我认为User.php(model)中可能存在问题


Auth::trunt()函数会自动对密码进行哈希运算。问题是您将密码存储为纯文本。因此,当该方法检查密码是否正确时,它会对密码进行哈希运算,并将其与保存的密码进行比较。该密码不是散列的,所以除非您在注册表中对密码进行散列,否则它不会工作

注册用户时是否对密码进行哈希处理?我在任何地方都看不到…给我们看看你的注册表控制器,我感觉您正在以明文形式存储密码。我现在添加了我的RegisterController.php和model/Register.php文件。是的,我的密码以明文形式存储在表中。这是主要问题。我已经解决了。谢谢您的回复。我刚刚在model/Register.php中更改了代码。上面我添加了我编辑的密码Register.php
    @extends('layout')

    @section('main')
    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Registrationhhjh</title>
    </head>
    <body>

        <section class="header">
        <div class="bannner">&nbsp;</div>
        <div class="container">
            <h1>Sign In</h1>

            @if ($errors->any())

            <ul style="color:red;">

            {{ implode('', $errors->all('<li>:message</li>')) }}

            </ul>

            @endif

  {{ Form::open(array('url' => 'logincheck')) }}
             {{ Form::text('name', '', array('placeholder'=>'Name')) }}<br><br>
            {{ Form::password('password', '', array('placeholder'=>'Password')) }}<br><br>
            {{ Form::submit('Sign in', array('class'=>'btn btn-success')) }}
            <!-- {{ Form::submit('register', array('class'=>'btn btn-primary')) }} -->
            {{ HTML::link('register', 'Register', array('class' => 'btn btn-info'))}}

            {{ Form::close() }}



           </div>

        </section>





    </body>
    </html>

    @stop
<?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;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'registered_users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password', 'remember_token');
    //protected $hidden = array('password');

    public function getAuthIdentifier()
  {
    return $this->getKey();
  }
  public function getAuthPassword()
  {
    return $this->password;
  } 
  public function getRememberToken()
  {
    return $this->remember_token;
  }
  public function setRememberToken($value)
  {
    $this->remember_token = $value;
  }
    public function getRememberTokenName()
  {
    return "remember_token";
  }
  public function getReminderEmail()
  {
    return $this->email;
  }

}
<?php

return array(

    /*
    |--------------------------------------------------------------------------
    | Default Authentication Driver
    |--------------------------------------------------------------------------
    |
    | This option controls the authentication driver that will be utilized.
    | This driver 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.
    |
    | The "expire" time is the number of minutes that the reminder should be
    | considered valid. This security feature keeps tokens short-lived so
    | they have less time to be guessed. You may change this as needed.
    |
    */

    'reminder' => array(

        'email' => 'emails.auth.reminder',

        'table' => 'password_reminders',

        'expire' => 60,

    ),

);
<?php

class RegisterController extends BaseController {

    /*
    |--------------------------------------------------------------------------
    | Default Home Controller
    |--------------------------------------------------------------------------
    |
    | You may wish to use controllers instead of, or in addition to, Closure
    | based routes. That's great! Here is an example controller method to
    | get you started. To route to this controller, just add the route:
    |
    |   Route::get('/', 'HomeController@showWelcome');
    |
    */


    // public function store()
    // {
 //        Register::saveFormData(Input::except(array('_token')));
 //    }

    public function store()
    {
            $data =  Input::except(array('_token')) ;
            $rule  =  array(
                    'name'       => 'required|unique:registered_users',
                    'email'      => 'required|email|unique:registered_users',
                    'password'   => 'required|min:6|same:cpassword',
                    'cpassword'  => 'required|min:6'
                ) ;
            $message = array(
                   'cpassword.required' => 'The confirm password field is required.',
                   'cpassword.min'      => 'The confirm password must be at least 6 characters',
                   'password.same'      => 'The :attribute and confirm password field must match.',
               );
            $validator = Validator::make($data,$rule,$message);

           // $validator = Validator::make($data,$rule);

            if ($validator->fails())
            {
                    return Redirect::to('register')
                            ->withErrors($validator->messages());
            }
            else
            {
                    Register::saveFormData(Input::except(array('_token','cpassword')));

                    return Redirect::to('register')
                            ->withMessage('Successfully registered');
            }
    }

}
<?php

class Register extends Eloquent {
        protected $guarded = array();
        protected $table = 'registered_users'; // database table name
        public $timestamps = 'false' ; // to disable default timestamp fields

        // model function to store form data to database
        public static function saveFormData($data)
        {
            DB::table('registered_users')->insert($data);
        }

}
<?php

class Register extends Eloquent {
        protected $guarded = array();
        protected $table = 'registered_users'; // database table name
        public $timestamps = 'false' ; // to disable default timestamp fields

        // model function to store form data to database
        public static function saveFormData($data)
        {
          //  DB::table('registered_users')->insert($data);
                $name = Input::get('name');
                $email = Input::get('email');
                $password = Hash::make(Input::get('password'));


                $user = new User;

                $user->name = $name;
                $user->email = $email;
                $user->password = $password;

                $user->save();
        }

}