As a developer working with Laravel 10, ensuring the security of user accounts and data is a top priority. One of the fundamental aspects of user security is implementing robust password and password confirmation validation during the registration process.
In this step-by-step guide, I'll take you through the process of setting up password and password confirmation validation in Laravel 10, allowing you to enforce strong password requirements and ensuring that users confirm their chosen passwords accurately.
So, let's see laravel 10 password and confirm password validation, password and confirm password validation in laravel 10, how to validate a password and confirm password.
If you haven't already, create a new Laravel 10 project using Composer.
composer create-project laravel/laravel password-confirmation-validation
cd password-confirmation-validation
In the validator
method, add validation rules for the password
and password_confirmation
fields.
public function store(Request $request): RedirectResponse
{
$this->validate($request, [
'name' => 'required',
'email' => 'required|email',
'password' => 'required|confirmed|min:6',
'password_confirmation' => 'required'
]);
}
The 'confirmed'
rule ensures that the password
field matches the password_confirmation
field.
Open the form view, Make sure the form includes an input for the password and a confirmation input.
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password">
@if ($errors->has('password'))
<span class="help-block text-danger">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password_confirmation">
@if ($errors->has('password_confirmation'))
<span class="help-block">
<strong>{{ $errors->first('password_confirmation') }}</strong>
</span>
@endif
</div>
</div>
With the changes made, you can now run your Laravel 10 application.
php artisan serve
You've now successfully implemented password and confirmation password validation in your Laravel 10 application.
You might also like:
- Read Also: How to Validate Array Input in Laravel 10
- Read Also: How to Sorting Column in Table in Laravel 10
- Read Also: How to Validate Form using Validate.js in Laravel 10
- Read Also: Laravel 10 Many To Many Polymorphic Relationship