Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

< GDB >'s avatar

Password validation error message not shown

Hey,

After playing around with my registration, login, reset psw setup I noticed that during registration the passwords were not being verified. (!= identical passwords were still being processed)

Resolved that but now it does not show any message if the passwords are not matched.

This is how my register.blade.php looks like (only part containing psw) :

<div class="form-group">
    <label for="password">Password</label>
    <input class="form-control @error('password') is-invalid @enderror" name="password" type="password" 
    required autocomplete="new-password" placeholder="Enter your password">
                                        
    
    @error('password')
        <span class="invalid-feedback" role="alert">
            <strong>{{ $message }}</strong>
        </span>
    
    @enderror
</div>

<div class="form-group">
    <label for="password-confirm">Confirm password</label>
    <input class="form-control" name="confirm_password" type="password" 
    required id="password-confirm" autocomplete="new-password" placeholder="Confirm your password">                                       
</div>

This is how the validator is set up :

protected function validator(array $data)
{
    // dd($data);
    return Validator::make($data, [

        'firstname' => ['required', 'string', 'max:255'],
        'lastname' => ['required', 'string', 'max:255'],
        'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
        'password' => ['required', 'string', 'min:8', 'required_with:confirm_password|same:confirm_password'],
        'confirm_password' => ['required', 'string', 'min:8'],

    ]);
}

Before I'm trying to fetch it to far, did i make a mistake in the validator function?

0 likes
3 replies
rodrigo.pedra's avatar
Level 56

Use the confirmed validation rule:

protected function validator(array $data)
{
    // dd($data);
    return Validator::make($data, [

        'firstname' => ['required', 'string', 'max:255'],
        'lastname' => ['required', 'string', 'max:255'],
        'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
        'password' => ['required', 'string', 'min:8', 'confirmed'], // changed here
        // 'confirm_password' => ['required', 'string', 'min:8'], // can even remove this
    ]);
}

But the confirmation field should be named password_confirmation as such:

<div class="form-group">
    <label for="password">Password</label>
    <input class="form-control @error('password') is-invalid @enderror" name="password" type="password" 
    required autocomplete="new-password" placeholder="Enter your password">
                                        
    
    @error('password')
        <span class="invalid-feedback" role="alert">
            <strong>{{ $message }}</strong>
        </span>
    
    @enderror
</div>

<div class="form-group">
    <label for="password-confirm">Confirm password</label>
    <input class="form-control" name="password_confirmation" type="password" 
    required id="password-confirm" autocomplete="new-password" placeholder="Confirm your password">                                       
</div>

Note that I just set the name attribute to password_confirmation as that is what is sent to the server. You can change the id to match it if you want.

Reference: https://laravel.com/docs/8.x/validation#rule-confirmed

< GDB >'s avatar

thank you a lot for that.

In the meantime I had read that I had to use the name field "password_confirmation" but did not understand / get / read that (and why) I had to change my validator $data. Which I didn't do, resulting in the reload of page with no error warning.

@rodrigo.pedra Where did you read / how did you know you had to change the validator $data input / conditions?

Thanks again!

1 like
rodrigo.pedra's avatar

The docs link I sent in my last response explains the rationale behind it.

Basically when using confirmed the validator will search for an additional field named similar with the _confirmed suffix and compare both

1 like

Please or to participate in this conversation.