douxianji6104 2018-05-15 05:18
浏览 60
已采纳

如何使用laravel 5.4中的会话登录

I am a newbie in laravel. I made a registration and logged in form. The user can register himself but I am unable to create logged in form appropriately. I want to able the user to logged in with session on correct information of username and password.

here is my controller:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use Auth;

class tuto extends Controller
{
    public function login(){
        return view('pages.login');
    }

    public function login_validation(Request $request){
        $this->validate($request, [
    'username' => 'required|min:3|max:10',
     'password' => 'required|min:6',

    ]);

    if(Auth::attempt(['name'=>$request->username,'password'=>$request->password])){
        return "true";
        }

    return 'false';
    }

}

I am getting false message even on correct username and password. here is my logged in page:

<form method="POST" action="/login" autocomplete="off">

        <input type="hidden" name="_token" value="{{ csrf_token() }}">


        <div class="row">
            <div class="col-md-offset-4 col-md-4">
                <div class="form-group">
                    <label for="username">Username:</label>
                    <input type="text" id="username" name="username" class="form-control" placeholder="Enter Username">
                </div>
            </div>



            <div class="col-md-offset-4 col-md-4">
                <div class="form-group">
                    <label for="password">Password:</label>
                <input type="password" id="password" name="password" class="form-control" placeholder="Enter Password">

                </div>
            </div>
        </div>



        <div class="form-group" align="center">
            <button class="btn btn-success">LogIn</button>

        </div>
        <div align="center"> Don't have an account ?  <a href="/register"> SignUp </a> </div>

</form>

also I want to create session on successful authentication. any help would be highly appreciable. Thank you

  • 写回答

2条回答 默认 最新

  • duanlushen8940 2018-05-15 05:26
    关注

    To avoid these kind of errors. Use laravel's build-in authentication system.

    1.create new laravel app laravel new my-project

    2.cd into my-project and type php artisan make:auth

    This will create a basic authentication system with all login and registration routes, controllers and views

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!