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条)

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: