UppercaseLength.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Rules;
  3. use Illuminate\Contracts\Validation\Rule;
  4. class UppercaseLength implements Rule
  5. {
  6. private int $passwordUppercaseLength = 0;
  7. /**
  8. * Create a new rule instance.
  9. *
  10. * @return void
  11. */
  12. public function __construct()
  13. {
  14. // 비밀번호 유효성 검사 규칙 지정
  15. $this->passwordUppercaseLength = config('password_uppercase_length', 0);
  16. }
  17. /**
  18. * Determine if the validation rule passes.
  19. *
  20. * @param string $attribute
  21. * @param mixed $value
  22. * @return bool
  23. */
  24. public function passes($attribute, $value)
  25. {
  26. // 대문자 포함 여부
  27. return ($this->passwordUppercaseLength > 0 ? countUppercase($value) >= $this->passwordUppercaseLength : true);
  28. }
  29. /**
  30. * Get the validation error message.
  31. *
  32. * @return string
  33. */
  34. public function message()
  35. {
  36. return sprintf("비밀번호에는 %d개 이상의 대문자를 포함해야 합니다.", $this->passwordUppercaseLength);
  37. }
  38. }