-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Profile; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Validation\Rules\Password; | ||
use Illuminate\Validation\Validator; | ||
|
||
class UpdatePasswordRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'current_password' => ['required', 'string', 'max:255'], | ||
'password' => [ | ||
'required', | ||
'string', | ||
Password::min(8)->mixedCase()->numbers()->symbols(), | ||
'confirmed', | ||
'max:255' | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Configure the validator instance. | ||
* | ||
* @param Validator $validator | ||
* @return void | ||
*/ | ||
public function withValidator(Validator $validator): void | ||
{ | ||
$validator->after(function ($validator) { | ||
if (!Hash::check($this->input('current_password'), $this->user()->password)) { | ||
$validator->errors()->add( | ||
'current_password', | ||
__('The password provided does not match your current password.') | ||
); | ||
} | ||
}); | ||
} | ||
} |