TechvBlogs
Published in

TechvBlogs

Password and Confirm Password Validation in Laravel

Feb 20, 2022, Originally published at techvblogs.com ・2 min read

Introduction

Laravel form requests are special classes that extend the functionality of regular request classes, enabling advanced validation features. Form requests also help to keep your controller actions a lot cleaner, because you can move all your validation logic to the form request class. Another benefit is that it allows you to filter requests before they reach your controller actions.

It’s always a good idea to put a password confirmation field in your forms since the password is a masked field and the user would never know if they made a typing mistake while filling out the password.

On the backend validation, you just need to use the confirmed validation rule for your password field.

$request->validate([
'password' => 'required|confirmed|min:6'
]);

Also in your HTML, you need to make sure the password field used to input confirmation from the user must be named password_confirmation.

<input id="password" type="password" name="password_confirmation" required>

Bootstrap FrontEnd Code for Laravel Password and Confirm Password Validation

Here is the bootstrap form code that includes both the fields and also displays an error when the validation fails.

<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="current-password">
@error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">Confirm Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password_confirmation" required autocomplete="current-password">
</div>
</div>

Thank you for reading this blog.

--

--

--

We are sharing Blogs that are related to 🌍 Web and 📱 Mobile Applications issues and examples of Development. We are share blogs related to Laravel, PHP, CodeIgniter, HTML, CSS, Bootstrap, Javascript, jQuery, MySQL, MongoDB, Node.js, Vue.js, Nuxt.js.

Recommended from Medium

BEGINNERS GUIDE TO LARAVEL 9 LUMEN : HOW TO CREATE RESTful APIs WITH LUMEN 9

Why Rust is getting popular?

Turn cache on in HCL Commerce v9

Docker Registry

My Algo-Trading Environment

Life is a journey of twists and turns, peaks and valleys, mountains to climb and oceans to explore.

Low-Code, No-Code: Software Development and Programming Outlook

Selenium chromedriver errors in Mac

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Smit Pipaliya

Smit Pipaliya

I am Senior Developer at ServerAvatar Technology.

More from Medium

How to Clear Cache In Laravel 8

Simple roles and permissions package for Laravel

How is Laravel work?

How Laravel work

Laravel Advance | Laravel 7/6 Cron Job Task Scheduling Tutorial