krgm.so-manager-dev.com/app/Http/Requests/ChangePasswordRequest.php
OU.ZAIKOU 6aa82dde3b
All checks were successful
Deploy main / deploy (push) Successful in 22s
【定期パスワード変更】実装
2026-01-27 01:13:17 +09:00

98 lines
3.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Password;
class ChangePasswordRequest extends FormRequest
{
/**
* リクエストを処理することを認可するか判定
*
* @return bool
*/
public function authorize(): bool
{
return auth()->check();
}
/**
* 入力値の検証ルール
*
* クライアント側必填3項目、長度 8-64、新密码仅半角英数字+记号、新/确认一致
* サーバー側当前密码认证hash check、新密码不能等于旧密码CustomRulesで実装
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
// 当前パスワード必填、8-64文字
'current_password' => [
'required',
'string',
'min:8',
'max:64',
],
// 新パスワード必填、8-64文字、英数字+記号のみ
'password' => [
'required',
'string',
'min:8',
'max:64',
'regex:/^[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};:\'",.<>?\/\\|`~]+$/', // 半角英数字+記号のみ
],
// 新パスワード確認:必填、新パスワードと一致
'password_confirmation' => [
'required',
'string',
'same:password',
],
// hidden フィールド(フォーム側で出力)
'updated_at' => 'nullable|date_format:Y-m-d H:i:s',
'ope_pass_changed_at' => 'nullable|date_format:Y-m-d H:i:s',
];
}
/**
* 属性の表示名
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'current_password' => '当前パスワード',
'password' => '新パスワード',
'password_confirmation' => '新パスワード確認',
];
}
/**
* 検証エラーメッセージのカスタマイズ
*
* @return array<string, string>
*/
public function messages(): array
{
return [
'current_password.required' => '当前パスワードを入力してください。',
'current_password.min' => '当前パスワードは8文字以上です。',
'current_password.max' => '当前パスワードは64文字以下です。',
'password.required' => '新パスワードを入力してください。',
'password.min' => '新パスワードは8文字以上です。',
'password.max' => '新パスワードは64文字以下です。',
'password.regex' => '新パスワードは英数字と記号のみ使用できます。',
'password_confirmation.required' => '新パスワード確認を入力してください。',
'password_confirmation.same' => '新パスワードと新パスワード確認は一致する必要があります。',
];
}
}