Skip to content

Commit

Permalink
Feat: 회원가입 시 비밀번호 예외 처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yxhwxn committed Jul 29, 2024
1 parent 9e7178a commit db18445
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class JoinDTO {
private String name;

@NotBlank(message = "비밀번호를 입력해주세요")
@Pattern(regexp = "(?=.*[0-9])(?=.*[a-zA-Z])(?=.*\\W)(?=\\S+$).{8,16}", message = "비밀번호는 8~16자 영문, 숫자, 특수문자를 사용하세요.")
@Pattern(regexp = "(?=.*[0-9])(?=.*[a-zA-Z])(?=.*\\W)(?=\\S+$).{8,20}", message = "비밀번호는 8~20자 영문, 숫자, 특수문자를 사용하세요.")
private String password;

@NotBlank(message = "이메일을 입력해주세요")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public Member join(MemberRequestDTO.JoinDTO request) {
throw new IllegalArgumentException("이미 존재하는 유저입니다.");
}

// 비밀번호 조건 검증
String password = request.getPassword();
if (!isValidPassword(password)) {
throw new IllegalArgumentException("비밀번호는 8~20자 영문, 숫자, 특수문자를 사용해야 합니다.");
}

// DTO를 Entity로 변환
Member member = memberConverter.toEntity(request, bCryptPasswordEncoder);

Expand All @@ -42,6 +48,11 @@ public Member join(MemberRequestDTO.JoinDTO request) {
return member;
}

// 비밀번호 조건 검증 메서드
private boolean isValidPassword(String password) {
return password.matches("(?=.*[0-9])(?=.*[a-zA-Z])(?=.*\\W)(?=\\S+$).{8,20}");
}

/**
* ID 중복 확인
*/
Expand Down

0 comments on commit db18445

Please sign in to comment.