0

i'm coding an application with laravel and since i'm still a beginner i got stuck on the login part , i didn't use the authentication library for some specefic details but now when i want to store the connected user identity values i don't know how to do it , i tried to use session variables but i always get null on them , take this as an example :

public function authenticate(Request $request)
{
    //$credentials = $request->only('Email', 'password');
    $email = Str::lower($request->input('Email'));
    $password = $request->input('password');
    $Ftime = $request->input('Ftime');
    $currentDateTime = Carbon::now();
    $user = User::where('Email', $email)->first();
    if ($currentDateTime->isAfter($Ftime)) {
        $user->update(['Password' => Str::random(60)]);

        $request->session->put(['Cuser'=>$user]);

        return redirect('login')->with('user',$user);
    }
    if ($user) {
        echo "that's it 1";
        if($user->Password == $password){
        // Authentication successful
        echo "that's it 2";
        return redirect('/home')->with('user',Auth::user());
    }
        else{
            echo "that's it 3";

            return view('errors/pass',['pass'=>$password]);
        }
    } else {
        // Authentication failed
        echo "that's it 4";
        return view('errors/email', ['error' => $email]);        
    }
}

what i want is when the user pass the password the $Cuser variable needs to be created between different routes and can be retrieved in different views

Set Kyar Wa Lar
  • 4,488
  • 4
  • 30
  • 57
  • 1
    Just use the built-in authentication system. There's no reason to make it so hard on yourself. – ceejayoz Aug 16 '23 at 15:12
  • i'm creating an application for a small company and they asked for theses features (a password that needs to be sent in each login) but i think i will try to fit it in the authentication option – Youssef Elhejjioui Aug 17 '23 at 08:19
  • As a beginner, you'll have the temptation to say "I'll try" to requests like this. As you become an expert, experience will tell you sometimes the answer is "Why? No!" – ceejayoz Aug 17 '23 at 13:07

0 Answers0