I made a login system but it says the login details are wrong and cannot log in
P粉946336138
P粉946336138 2024-03-20 00:21:28
0
1
349

I want to create simple login system and I made a login system but it says the login details are wrong. My attempt to do a dump test returns null. See the dd test in the comments. Unable to log out for this reason

My login controller is:

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

My login blade is

@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粉946336138
P粉946336138

reply all(1)
P粉710454910

Try debugging your code

1- Check the database after registration. Is your password encrypted?

2-When submitting the form dd($request->all()) if everything goes well

3- Auth::attempt($request->only('email', 'password'))

I hope this answer helps you debug your code.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template