Password reset helps users get a new password if they forget the old one. It keeps accounts safe and easy to access again.
0
0
Password reset in Laravel
Introduction
When a user forgets their password and cannot log in.
When you want to allow users to change their password securely.
When you want to improve user experience by providing a simple way to recover access.
When you want to keep user accounts secure by verifying identity before changing passwords.
Syntax
Laravel
php artisan ui vue --auth // Use built-in Laravel routes and controllers for password reset // Routes in routes/web.php Route::get('password/reset', [ForgotPasswordController::class, 'showLinkRequestForm'])->name('password.request'); Route::post('password/email', [ForgotPasswordController::class, 'sendResetLinkEmail'])->name('password.email'); Route::get('password/reset/{token}', [ResetPasswordController::class, 'showResetForm'])->name('password.reset'); Route::post('password/reset', [ResetPasswordController::class, 'reset'])->name('password.update');
Laravel provides built-in controllers and views for password reset.
You can customize email templates and views if needed.
Examples
This route shows the form where users enter their email to get a reset link.
Laravel
// Show form to request password reset link Route::get('password/reset', [ForgotPasswordController::class, 'showLinkRequestForm'])->name('password.request');
This route sends the reset link email after user submits their email.
Laravel
// Send password reset email Route::post('password/email', [ForgotPasswordController::class, 'sendResetLinkEmail'])->name('password.email');
This route shows the form where user enters a new password after clicking the email link.
Laravel
// Show form to reset password using token Route::get('password/reset/{token}', [ResetPasswordController::class, 'showResetForm'])->name('password.reset');
This route processes the new password and updates it securely.
Laravel
// Update password in database Route::post('password/reset', [ResetPasswordController::class, 'reset'])->name('password.update');
Sample Program
This example shows a simple controller to display the password reset request form and send the reset email. The routes connect to these controller methods.
Laravel
<?php namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\Password; class ForgotPasswordController extends Controller { public function showLinkRequestForm() { return view('auth.passwords.email'); } public function sendResetLinkEmail(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)]); } } // In routes/web.php use App\Http\Controllers\Auth\ForgotPasswordController; Route::get('password/reset', [ForgotPasswordController::class, 'showLinkRequestForm'])->name('password.request'); Route::post('password/email', [ForgotPasswordController::class, 'sendResetLinkEmail'])->name('password.email');
OutputSuccess
Important Notes
Make sure your mail settings in .env are configured to send emails.
Laravel stores reset tokens securely and expires them after a set time.
You can customize views in resources/views/auth/passwords/ for branding.
Summary
Password reset lets users recover access safely.
Laravel has built-in routes and controllers to handle this easily.
Always validate user input and configure email sending properly.