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 CCF-CSP 2023 第三题 解压缩(50%)
  • ¥30 comfyui openpose报错
  • ¥20 Wpf Datarid单元格闪烁效果的实现
  • ¥15 图像分割、图像边缘提取
  • ¥15 sqlserver执行存储过程报错
  • ¥100 nuxt、uniapp、ruoyi-vue 相关发布问题
  • ¥15 浮窗和全屏应用同时存在,全屏应用输入法无法弹出
  • ¥100 matlab2009 32位一直初始化
  • ¥15 Expected type 'str | PathLike[str]…… bytes' instead
  • ¥15 三极管电路求解,已知电阻电压和三级关放大倍数