I want to create form with 3 field (old_password, new_password, confirm_password) with laravel 5.
View
old password :
{!! Form::password(
changePassword.blade.php
@extends('layouts.app')
@section('content')
@endsection
Controller Post Function
public function postChangePassword(Request $request)
{
$validatedData = $request->validate([
'oldpass' => 'required|min:6',
'password' => 'required|string|min:6',
'password_confirmation' => 'required|same:password',
],[
'oldpass.required' => 'Old password is required',
'oldpass.min' => 'Old password needs to have at least 6 characters',
'password.required' => 'Password is required',
'password.min' => 'Password needs to have at least 6 characters',
'password_confirmation.required' => 'Passwords do not match'
]);
$current_password = \Auth::User()->password;
if(\Hash::check($request->input('oldpass'), $current_password))
{
$user_id = \Auth::User()->id;
$obj_user = User::find($user_id);
$obj_user->password = \Hash::make($request->input('password'));
$obj_user->save();
return view('auth.passwords.changeConfirmation');
}
else
{
$data['errorMessage'] = 'Please enter correct current password';
return redirect()->route('user.getChangePassword', $data);
}
}