Laravel Auth :: attempt /登录页面无法正常工作

博尔纳

我的注册页面运行正常。数据已正确插入到名为“ 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');

});

我检查路线::后(“logincheck”,()函数routes.php文件一步一步...一切正常......但是下面的部分路线::后(“logincheck”,()函数routes.php文件无法正常工作。无论我输入正确的用户名和密码还是登录表单中的错误,它只会显示“错误的登录详细信息”消息

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

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

User.php(model)。我认为User.php(model)可能有问题

<?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;
  }

}

auth.php ..有人可以告诉我什么是'table'=>'users',auto.php中吗?....一旦我将其重命名为'table'=>'registered_users',因为我没有命名为'users'的用户table。但是问题仍然存在(同样,我无法进入“主页”)

<?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,

    ),

);

我使用WAMP server..i使用laravel 4.2..my数据库名称MYDB ...表名registered_users表都有编号姓名电子邮件密码remember_tokencreated_at的updated_at领域

Remember_token字段类型为varchar(270)...是否对Remember_token大小有任何限制

请帮助我任何人登录系统有什么问题?

这是我的RegisterController.php

<?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');
            }
    }

}

这是model / Register.php

<?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);
        }

}

终于我解决了我的问题。我的问题是我将密码存储为plaintext.for解决我的问题,我只是编辑了我的models \ Register.php文件。这是我编辑的模型\ Register.php

<?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();
        }

}
马尔滕00

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Laravel Auth :: attempt / login页面无法正常工作

来自分类Dev

Laravel 4-Auth :: attempt()无法正常工作并返回FALSE

来自分类Dev

Laravel 5.5 中的 auth()->attempt() 无法正常工作

来自分类Dev

Laravel登录(Auth :: attempt)不起作用

来自分类Dev

Laravel Auth :: attempt()实际未登录

来自分类Dev

Laravel Auth :: attempt()返回false

来自分类Dev

Laravel Auth :: attempt()始终将我重定向到登录页面

来自分类Dev

Laravel 5 Auth :: attempt总是返回false

来自分类Dev

Laravel 5 Auth :: attempt()总是返回false

来自分类Dev

Laravel Auth :: attempt函数不起作用

来自分类Dev

laravel 4.2中的Auth :: attempt()正确用法

来自分类Dev

Laravel 5 Auth :: attempt()总是返回false

来自分类Dev

Laravel 5.3 Auth :: attempt()始终返回false

来自分类Dev

Laravel 5.1 注册 Auth::attempt 后无法访问另一个页面上的用户数据

来自分类Dev

如何在Laravel Auth :: attempt中使用条件参数?

来自分类Dev

Laravel还记得我,使用Auth :: attempt运行吗?

来自分类Dev

Laravel还记得我,使用Auth :: attempt运行吗?

来自分类Dev

Laravel 4:对不同表中的字段使用Auth :: attempt

来自分类Dev

Laravel:将数据传递到会话和auth :: attempt

来自分类Dev

laravel 5.1 Auth :: check()在JWTAuth :: attempt($ credentials)登录后出现500个内部服务器错误

来自分类Dev

Laravel auth :: attempt返回true,但是auth :: check()false为什么呢?

来自分类Dev

Laravel Auth无法正常工作,一切似乎正确

来自分类Dev

Android登录页面无法正常工作

来自分类Dev

Laravel Auth :: login($ user)不能正常工作

来自分类Dev

无法使用laravel auth登录/注册

来自分类Dev

Laravel 5无法使用Auth用户登录

来自分类Dev

Laravel 4 Auth :: attempt($ userdata,false)身份验证仍然保留

来自分类Dev

如何在Laravel 4上执行自定义auth :: attempt消息

来自分类Dev

Laravel v5.2。*(v5.2.29)Auth :: guard('api')-> attempt($ user)致命错误

Related 相关文章

  1. 1

    Laravel Auth :: attempt / login页面无法正常工作

  2. 2

    Laravel 4-Auth :: attempt()无法正常工作并返回FALSE

  3. 3

    Laravel 5.5 中的 auth()->attempt() 无法正常工作

  4. 4

    Laravel登录(Auth :: attempt)不起作用

  5. 5

    Laravel Auth :: attempt()实际未登录

  6. 6

    Laravel Auth :: attempt()返回false

  7. 7

    Laravel Auth :: attempt()始终将我重定向到登录页面

  8. 8

    Laravel 5 Auth :: attempt总是返回false

  9. 9

    Laravel 5 Auth :: attempt()总是返回false

  10. 10

    Laravel Auth :: attempt函数不起作用

  11. 11

    laravel 4.2中的Auth :: attempt()正确用法

  12. 12

    Laravel 5 Auth :: attempt()总是返回false

  13. 13

    Laravel 5.3 Auth :: attempt()始终返回false

  14. 14

    Laravel 5.1 注册 Auth::attempt 后无法访问另一个页面上的用户数据

  15. 15

    如何在Laravel Auth :: attempt中使用条件参数?

  16. 16

    Laravel还记得我,使用Auth :: attempt运行吗?

  17. 17

    Laravel还记得我,使用Auth :: attempt运行吗?

  18. 18

    Laravel 4:对不同表中的字段使用Auth :: attempt

  19. 19

    Laravel:将数据传递到会话和auth :: attempt

  20. 20

    laravel 5.1 Auth :: check()在JWTAuth :: attempt($ credentials)登录后出现500个内部服务器错误

  21. 21

    Laravel auth :: attempt返回true,但是auth :: check()false为什么呢?

  22. 22

    Laravel Auth无法正常工作,一切似乎正确

  23. 23

    Android登录页面无法正常工作

  24. 24

    Laravel Auth :: login($ user)不能正常工作

  25. 25

    无法使用laravel auth登录/注册

  26. 26

    Laravel 5无法使用Auth用户登录

  27. 27

    Laravel 4 Auth :: attempt($ userdata,false)身份验证仍然保留

  28. 28

    如何在Laravel 4上执行自定义auth :: attempt消息

  29. 29

    Laravel v5.2。*(v5.2.29)Auth :: guard('api')-> attempt($ user)致命错误

热门标签

归档