라라벨
laravel reset password min:6 라라벨 패스워드리셋 6자리
땀모
2019. 9. 5. 04:42
라라벨5.8 기준 작성
회원가입 패스워드는 유효성검사로 6자리 가능하지만 리셋 패스워드는 그렇지 않다.
그래서 rules() 해도 무시된다.
아래의 기존 코드를 변경하면 6자리로 가능해진다.
기존 코드 /vendor/laravel/framework/src/Illuminate/Foundation/Auth/
ResetPassword.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | public function reset(Request $request) { $request->validate($this->rules(), $this->validationErrorMessages()); // Here we will attempt to reset the user's password. If it is successful we // will update the password on an actual user model and persist it to the // database. Otherwise we will parse the error and return the response. $response = $this->broker()->reset( $this->credentials($request), function ($user, $password) { $this->resetPassword($user, $password); } ); // If the password was successfully reset, we will redirect the user back to // the application's home authenticated view. If there is an error we can // redirect them back to where they came from with their error message. return $response == Password::PASSWORD_RESET ? $this->sendResetResponse($request, $response) : $this->sendResetFailedResponse($request, $response); } | cs |
6자리 변경코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public function reset(Request $request) { $request->validate($this->rules(), $this->validationErrorMessages()); $this->broker()->validator(function (array $credentials){ [$password, $confirm] = [ $credentials['password'], $credentials['password_confirmation'], ]; return $password === $confirm && mb_strlen($password) >= 6; }); $response = $this->broker()->reset( $this->credentials($request), function ($user, $password) { $this->resetPassword($user, $password); } ); return $response == Password::PASSWORD_RESET ? $this->sendResetResponse($request, $response) : $this->sendResetFailedResponse($request, $response); } | cs |
rules, Messages
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | protected function rules() { return [ 'token' => 'required', 'email' => 'required|email', 'password' => 'required|confirmed|min:6', ]; } /** * Get the password reset validation error messages. * * @return array */ protected function validationErrorMessages() { return [ 'password.required' => '패스워드를 입력해 주세요.', 'password.min' => '패스워드는 6자리이상 입력해 주세요.', ]; } | cs |