Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class PasswordRequestDto(
val email: String,

@get:Pattern(
regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%^&*()]).{10,}\$",
regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9]).{10,}\$",
message = "비밀번호는 영어 대문자와 소문자, 숫자, 특수문자를 모두 포함하여 10자 이상이어야 합니다"
)
Comment on lines 11 to 14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

비밀번호 유효성 검사 정규식과 메시지가 여러 DTO에 중복으로 정의되어 있습니다. 이는 향후 비밀번호 정책 변경 시 여러 파일을 수정해야 하는 번거로움과 실수를 유발할 수 있습니다.

공통 상수로 분리하여 재사용성을 높이고 유지보수를 용이하게 하는 것을 권장합니다. 예를 들어, common 패키지 하위에 ValidationConstants와 같은 객체를 만들어 관리할 수 있습니다.

// common/validation/ValidationConstants.kt
object ValidationConstants {
    const val PASSWORD_REGEX = "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9]).{10,}\$"
    const val PASSWORD_MESSAGE = "비밀번호는 영어 대문자와 소문자, 숫자, 특수문자를 모두 포함하여 10자 이상이어야 합니다"
}

이렇게 하면 DTO에서는 다음과 같이 간결하게 사용할 수 있습니다.

@get:Pattern(
    regexp = ValidationConstants.PASSWORD_REGEX,
    message = ValidationConstants.PASSWORD_MESSAGE
)

val password: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import jakarta.validation.constraints.Pattern

data class PasswordRequestDto(
@get:Pattern(
regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%^&*()]).{10,}\$",
regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9]).{10,}\$",
message = "비밀번호는 영어 대문자와 소문자, 숫자, 특수문자를 모두 포함하여 10자 이상이어야 합니다"
)
Comment on lines 6 to 9

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

이 DTO에서도 비밀번호 유효성 검사 로직이 중복으로 정의되어 있습니다.

auth 패키지의 PasswordRequestDto에 제안한 것과 같이, 공통 상수를 만들어 중복을 제거하고 유지보수성을 향상시키는 것을 고려해 보세요.

val password: String
Expand Down
Loading