Author Login

Modern Authentication System in Laravel with Email Verification & Password Reset

๐Ÿ‘ค Marcus Johnson
20 Views
Oct 12, 2025
Contents

Installing Laravel Breeze

Laravel Breeze gives you a minimal, modern authentication scaffolding with Blade templates.

Use Composer to install it quickly.

Code Example (Terminal):

Language: BASH
composer require laravel/breeze --dev
php artisan breeze:install
npm install && npm run dev
php artisan migrate

Configuring .env and Mail Settings

For email verification and password reset, set your mail configuration.

Code Example (.env):

Language: BASH
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=yourmail@gmail.com
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=no-reply@surisnippet.com
MAIL_FROM_NAME="${APP_NAME}"

Registration Form

Breeze includes a pre-built register.blade.php, but you can customize it.

Code Example (Blade):

Language: HTML
<form method="POST" action="{{ route('register') }}">
  @csrf
  <input type="text" name="name" placeholder="Full Name" required>
  <input type="email" name="email" placeholder="Email Address" required>
  <input type="password" name="password" placeholder="Password" required>
  <button type="submit">Register</button>
</form>

Login Form

Allows users to access protected routes after registration.

Language: HTML
<form method="POST" action="{{ route('login') }}">
  @csrf
  <input type="email" name="email" placeholder="Email Address" required>
  <input type="password" name="password" placeholder="Password" required>
  <button type="submit">Login</button>
</form>

Controller Logic

Laravel handles the heavy lifting, but you can manually manage auth if needed.

Code Example (Controller Snippet):

Language: HTML
use Illuminate\Support\Facades\Auth;


public function login(Request $request)
{
  $credentials = $request->only('email', 'password');


  if (Auth::attempt($credentials, $request->filled('remember'))) {
    $request->session()->regenerate();
    return redirect()->intended('dashboard');
  }


  return back()->withErrors(['email' => 'Invalid credentials.']);
}

Enabling Email Verification

Add the MustVerifyEmail interface to your User model.

Language: PHP
class User extends Authenticatable implements MustVerifyEmail
{
  use Notifiable;
}

Protecting Routes with Middleware

Force users to verify their email before accessing protected pages.

Code Example (web.php):

Language: PHP
Route::get('/dashboard', function () {
  return view('dashboard');
})->middleware(['auth', 'verified']);

Enabling Email Verification

Add the MustVerifyEmail interface to your User model.

Language: PHP
class User extends Authenticatable implements MustVerifyEmail
{
  use Notifiable;
}

Protecting Routes with Middleware

Force users to verify their email before accessing protected pages.

Code Example (web.php):

Language: PHP
Route::get('/dashboard', function () {
  return view('dashboard');
})->middleware(['auth', 'verified']);

Customizing Verification Email

You can publish and customize the verification email template.

Language: BASH
php artisan vendor:publish --tag=laravel-notifications

Forgot Password Form

Users can request a reset link sent to their email.

<form method="POST" action="{{ route('password.email') }}">

  @csrf

  <input type="email" name="email" placeholder="Enter your email" required>

  <button type="submit">Send Reset Link</button>

</form>


Reset Password Form

The reset form appears when the user clicks the email link.

Language: HTML
<form method="POST" action="{{ route('password.update') }}">
  @csrf
  <input type="hidden" name="token" value="{{ $request->token }}">
  <input type="email" name="email" value="{{ $request->email }}" required>
  <input type="password" name="password" placeholder="New Password" required>
  <button type="submit">Reset Password</button>
</form>

Controller Logic for Password Reset

Code Example (PasswordResetController):

Language: PHP
use Illuminate\Support\Facades\Password;


public function sendResetLink(Request $request)
{
  $request->validate(['email' => 'required|email']);
  $status = Password::sendResetLink($request->only('email'));


  return $status === Password::RESET_LINK_SENT
    ? back()->with(['status' => __($status)])
    : back()->withErrors(['email' => __($status)]);
}

Restricting Auth Routes

Use middleware to protect user-only pages.

Language: PHP
Route::middleware(['auth'])->group(function () {
  Route::get('/profile', [ProfileController::class, 'index'])->name('profile');
});

Logging Out Securely

Always invalidate the session on logout.

Language: PHP
Route::post('/logout', function (Request $request) {
  Auth::logout();
  $request->session()->invalidate();
  $request->session()->regenerateToken();
  return redirect('/');
})->name('logout');

Tailwind Form Styles

Make your forms look clean and responsive.

Language: HTML
<input class="border rounded w-full p-2 focus:ring focus:ring-indigo-200" type="email">
<button class="w-full bg-indigo-600 text-white py-2 rounded mt-3 hover:bg-indigo-700">
 Login
</button>

Test Scenarios

  • Register โ†’ Check email โ†’ Verify โ†’ Login
  • Forgot password โ†’ Reset โ†’ Login again

Run locally:

Language: BASH
php artisan serve

Open http://127.0.0.1:8000

to test your flow.

About SuriSnippet

Know about our company more.

Contact Us

We are Here to Help

FAQ

Get all Answers