use Illuminate\Support\Facades\Auth; public function register(Request $request) { $validatedData = $request->validate([ 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 'password' => ['required', 'string', 'min:8', 'confirmed'], ]); $user = User::create([ 'name' => $validatedData['name'], 'email' => $validatedData['email'], 'password' => Hash::make($validatedData['password']), ]); Auth::login($user); return redirect('/dashboard'); }
if (isset($_POST['login'])) { $email = $_POST['email']; $password = $_POST['password']; $stmt = $pdo->prepare("SELECT * FROM users WHERE email=:email"); $stmt->execute(['email' => $email]); $user = $stmt->fetch(); if ($user && password_verify($password, $user['password'])) { $_SESSION['user_id'] = $user['id']; header("Location: /dashboard.php"); exit(); } else { $error = "Incorrect email or password!"; } }This code logs in a user by fetching their data from the database based on the email provided. It then verifies the password using PHP's Password Hashing Functions and logs the user in if the password is correct. This does not use any specific package/library.