I want to create form with 3 field (old_password, new_password, confirm_password) with laravel 5.
View
old password :
{!! Form::password('old_password',['class' => 'form-control']) !!}
New Password : {!! Form::password('password',['class' => 'form-control']) !!}
Confirm New Password : {!! Form::password('verify_password',['class' => 'form-control']) !!}
Controller when user register
public function postRegister(Request $request)
{
$rules = [
'email' => 'required|email|unique:users',
'confirm_email' => 'required|same:email',
'password' => 'required|min:8|regex:/^(?=\S*[a-z])(?=\S*[!@#$&*])(?=\S*[A-Z])(?=\S*[\d])\S*$/',
'verify_password' => 'required|same:password',
];
$messages = [
'email.required' => 'email tidak boleh kosong',
'password.required' => 'password tidak boleh kosong',
'password.min' => 'Password harus minimal 8 karakter',
'password.regex' => 'Format password harus terdiri dari kombinasi huruf besar, angka dan karakter spesial (contoh:!@#$%^&*?><).',
'verify_password.required' => 'Verify Password tidak boleh kosong',
'email.email' => 'Format Email tidak valid',
'email.unique' => 'Email yang anda masukkan telah digunakan',
'verify_password.same' => 'Password tidak sama!',
];
$this->validate($request,$rules,$messages);
$newUser = $this->user->create([
'email' => $request->email,
'password' => \Hash::make($request->password),
]);
$this->activationService->sendActivationMail($newUser);
return redirect('/account/login')->with('success', 'Check your email');
}
I'm new in laravel, i've read some similar problem to change password in stackoverflow but it didn't help me.
How should I write code in my controller for change password user?. Thanks in Advance.
I am explain here another method to change user password changepassword.blade.php
This is route in web.php
Controller Method
i have follow that link :- https://www.5balloons.info/setting-up-change-password-with-laravel-authentication/
Laravel 6 Check Old Password and Updating a New Password
This is change password form
Create rules
User controller method to changes password
use Validator;
This is how I do this with Laravel 5.8:
View
Confirm password must be something like this:
Because Laravel provides out the box a field confirmed rule.
Create a form request and put this inside the rules part:
Let's use artisan to generate a rule that verifies if
old_password
is the real current password:And put this inside the passes method of rule generated:
Do not forget to import
Hash
:Controller
All you need to do in your controller is this:
And tada :) Hope I help.
changePassword.blade.php
Controller Post Function