首页  >  问答  >  正文

我做了一个登录系统,但它说登录详细信息错误并且无法登录

我想创建简单的登录系统,并且我制作了一个登录系统,但它说登录详细信息错误。我尝试做转储测试返回 null。请参阅评论中的 dd 测试。由于这个原因也无法注销

我的登录控制器是:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
use Validator;

class LoginController extends Controller
{
    public function index()
    {
        return view('login');
    }

    
    public function store(Request $request)
    {
        $this->validate($request, [
            'email'   => 'required|email',
            'password'  => 'required|alphaNum|min:3'
                ]);

        $user_data = array(
            'email' => $request->get('email'),
            'password' => $request->get('password')
        );
        
        //$user = Auth::user();
        //dd($user);              I have done dump test but it is returning null
        
        if(Auth::attempt($user_data))
        {
            return redirect()->route('welcome');
        }
        else
        {
            return back()->with('error','wrong Login Details');
        }
    } 
}

我的登录刀片是

@if ($message = Session::get('error'))
                <div class="alert alert-danger alert-block">
                    <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong>{{ $message }}</strong>
                </div>
          @endif
           @if (count($errors) > 0)
            <div class="alert alert-danger">
                    <ul>
                            @foreach($errors->all() as $error)
                                <li>{{ $error }}</li>
                            @endforeach
                    </ul>
            </div>
           @endif
      
    <form action="{{route('login.save')}}" style="border:1px solid #ccc" method="post">
                {{ csrf_field() }}
        <div class="container">
            <h1>Login</h1>
            <p>Please fill in this form to Login</p>
            <hr>
            <label for="email"><b>Email</b></label>
            <input type="text" placeholder="Enter Email" name="email" value="{{old('name')}}" >
                @error('email')
                  {{$message}}
                @enderror  

            <label for="psw"><b>Password</b></label>
            <input type="password" placeholder="Enter Password" name="password"  >
                @error('password')
                  {{$message}}
                @enderror  

            <label for="psw-repeat"><b>Repeat Password</b></label>
            <input type="password" placeholder="Repeat Password" name="psw-repeat" >
            <div class="clearfix">
                <button type="submit" class="signupbtn">Log in</button>
            </div>
        </div>
    </form>
</body>
</html>

网络路由是

Route::get('/register','App\Http\Controllers\RegisterController@index')->name('register');
Route::post('/register/save','App\Http\Controllers\RegisterController@store')->name('register.save');
Route::get('/login','App\Http\Controllers\LoginController@index')->name('login');
Route::post('/login/save','App\Http\Controllers\LoginController@store')->name('login.save');
Route::get('/welcome','App\Http\Controllers\LogoutController@store')->name('logout');

P粉946336138P粉946336138234 天前326

全部回复(1)我来回复

  • P粉710454910

    P粉7104549102024-03-20 15:16:21

    尝试调试您的代码

    1- 注册后查看数据库。您的密码是否已加密?

    2-提交表单时 dd($request->all()) 如果一切顺利的话

    3- Auth::attempt($request->only('电子邮件', '密码'))

    我希望这个答案可以帮助您调试代码。

    回复
    0
  • 取消回复