Currently Available: Need a skilled Software Developer for your next project?
Categories
Laravel

Validating Passwords and Confirmation Fields in Laravel

When someone creates or resets a password in a Laravel form, the server should check that the password is present, meets the service’s password policy, and matches the confirmation entry. Laravel uses separate rules for these checks. required checks that the password is present; confirmed compares the entries. The Password rule checks configured password requirements.

A confirmation field asks the person to enter the password a second time, which helps catch typing mistakes. It does not measure password quality or check the person’s existing password. The examples below show how to combine Laravel’s rules and choose a password policy that fits the service.

Require a password and match its confirmation

For a field named password, Laravel’s confirmed rule expects a matching password_confirmation field. Both fields must appear in the submitted request:


The server can validate them together:

$request->validate([
    'password' => ['required', 'confirmed'],
]);

Here, required rejects a missing or blank password. confirmed checks that the confirmation entry is present and matches the password. Laravel documents the default field naming and custom confirmation fields.

To use a different confirmation field name, pass it to the rule:

$request->validate([
    'password' => ['required', 'confirmed:repeat_password'],
]);

Laravel then compares password with repeat_password. In either form, confirmation only checks that the entries agree. Laravel has a separate current_password rule for checking a submitted value against the authenticated user’s existing password, as shown in the validation documentation.

Add password-quality rules

required does not set a minimum length, reject a widely used password, or enforce any other quality standard. Add Laravel’s Password rule object to set those requirements:

use Illuminate\Validation\Rules\Password;

$request->validate([
    'password' => [
        'required',
        'confirmed',
        Password::min(15)->uncompromised(),
    ],
]);

This example requires a password and checks that its confirmation matches. It also sets a minimum length and rejects passwords found in public lists of passwords exposed in data breaches. Laravel also offers optional rules for letters, numbers, symbols, and mixed case. The exact configuration is your service’s policy; Laravel’s documented Password::min(8) example is not a universal requirement. See the Laravel password validation rules for the available options.

Laravel’s uncompromised() check uses k-anonymity with the Have I Been Pwned service. K-anonymity is a method that limits how much information the check reveals while comparing a password with breach data. Laravel’s default threshold treats a password found at least once as compromised, and the rule allows a different threshold. This check addresses breached passwords; it does not replace length requirements or every other part of a password policy.

Choose a policy that fits the service

Laravel lets developers set password rules. Security guidance defines requirements for specific types of authentication. For example, NIST SP 800-63B-4 specifies a minimum of 15 characters when a password is the only authentication factor. It permits a minimum of 8 characters when a password is one part of multi-factor authentication. NIST also advises against requiring combinations of character types, such as uppercase letters, numbers, and symbols. It says services that verify passwords should check new passwords against a blocklist of common, expected, or compromised values.

These recommendations are part of NIST’s digital identity guidance, so they do not set the policy for every service. When choosing Laravel rules, choose minimum and maximum password lengths for the way your service authenticates users, then decide which other checks to use. For a NIST-aligned maximum-length allowance, the verifier should permit at least 64 characters.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *