Home > Software engineering >  Laravel User Login Fail
Laravel User Login Fail

Time:02-04

i am going to make a login form with validation.if the username and password correct user shall be able to login other wise login failed.but i gave the correct username and password also login fail. i don't know why what i tried so far i attached below. password set as encrypted

LoginController

  public function check(Request $request)
    {  
       $credentials = [
                'email' => $request['email'],
               'password' =>  $request['password'],
            ];
         //   dd($credentials);
        $input['password'] = bcrypt($input['password']);

    
        if (Auth::attempt($request->only($credentials))) 
        {
            echo "Sucess";
        }
        echo "fail";

    }

Login view

@extends('layout')
@section('content')
  

    <div >
        <div >Contact Form</div>
        <div > 
        
            <form action= "{{ route('check') }}" method="post">
             {!! csrf_field() !!}   

            <label>Email</label>
            <input type="email" name="email" id="email" class ="form-control"> </br>


            <label>Password</label>
            <input type="password" name="password" id="password" class ="form-control"> </br>


            <input type="submit" value="Login" > 


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

@stop

CodePudding user response:

Please try this:

public function check(Request $request){ 

    $credentials = $request->validate([
        'email'     => ['required', 'email'],
        'password'  => ['required'],
    ]);

    if (Auth::attempt($credentials)) {
        echo "Sucess";
    }

    echo "fail";

}
  • Related