Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Password & Password_Confirmation Validation

I've been using this in order to edit the User Account Info:

$this->validate($request, [     'password' => 'min:6',     'password_confirmation' => 'required_with:password|same:password|min:6' ]); 

This worked fine in a Laravel 5.2 Application but does not work in a 5.4 Application.

image

What's wrong here, or what is the correct way in order to only make the password required if either the password or password_confirmation field is set?

like image 619
xTheWolf Avatar asked Mar 06 '17 10:03

xTheWolf


People also ask

How can I get Laravel password?

You cannot decrypt laravel password hash which is bcrypt. You can change it with new password. You can get the hashedPassword like this: $hashedPassword = Auth::user()->getAuthPassword();

What is password in Laravel?

The Laravel Hash facade provides secure Bcrypt and Argon2 hashing for storing user passwords. If you are using one of the Laravel application starter kits, Bcrypt will be used for registration and authentication by default.

How does Laravel hash password?

The Laravel Hash facade provides secure Bcrypt hashing for storing user passwords. If you are using the AuthController controller that is included with your Laravel application, it will be take care of verifying the Bcrypt password against the un-hashed version provided by the user.


2 Answers

You can use the confirmed validation rule.

$this->validate($request, [     'name' => 'required|min:3|max:50',     'email' => 'email',     'vat_number' => 'max:13',     'password' => 'required|confirmed|min:6', ]); 
like image 100
Neabfi Avatar answered Sep 24 '22 21:09

Neabfi


Try doing it this way, it worked for me:

$this->validate($request, [ 'name' => 'required|min:3|max:50', 'email' => 'email', 'vat_number' => 'max:13', 'password' => 'min:6|required_with:password_confirmation|same:password_confirmation', 'password_confirmation' => 'min:6' ]);` 

Seems like the rule always has the validation on the first input among the pair...

like image 28
omeatai Avatar answered Sep 21 '22 21:09

omeatai