SpecialCharLength.php 1018 B

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