In my application I have an area where user's can update their password by providing:
/**
* Change the password for the current logged in user
*
* @param Request $request
* @return void
*/
public function changePassword(UpdatePassword $request)
{
$data = $request->validated();
auth()->user()->update(['password' => $data['new-password']]);
event(new PasswordChanged(auth()->user()));
return redirect()->back()->with('success', 'Your password has been updated successfully');
}
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use LangleyFoxall\LaravelNISTPasswordRules\PasswordRules;
class UpdatePassword extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'current-password' => 'required|string',
'new-password' => array_merge(
[
'regex:/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{6,}$/',
],
PasswordRules::changePassword($this->email, $this->current_password),
),
];
}
/**
* Get the error messages for the defined validation rules.
*
* @return array
*/
public function messages()
{
return [
'current-password.required' => 'Please enter your current password',
'new-password.regex' => 'The password provided does not match the minimum strength requirement',
'new-password.different' => 'Please ensure your new password is different to your old password',
'new-password.confirmed' => 'Please ensure your new passwords match',
];
}
}
I've tried to simply pass in the email and pass, but they're not real properties.