-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 비밀번호 재설정 요청 시 요청 회원의 이메일로 재설정 임시 비밀번호를 담은 메일 전송 기능 2. 비밀번호 재설정 승인 시 메일에 포함된 임시 비밀번호로 비밀번호 재설정, 메인페이지로 이동 기능 Resolves: #149
- Loading branch information
Showing
13 changed files
with
271 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/darkoverload/itzip/feature/user/controller/request/PasswordResetRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package darkoverload.itzip.feature.user.controller.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.Pattern; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
/** | ||
* 비밀번호 재설정 요청 dto | ||
*/ | ||
@Getter | ||
@AllArgsConstructor | ||
public class PasswordResetRequest { | ||
@NotEmpty(message = "이메일을 입력해주세요.") | ||
@Pattern(regexp = "^[0-9a-zA-Z]([-_\\.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_\\.]?[0-9a-zA-Z])*\\.[a-zA-Z]{2,3}$", | ||
message = "올바르지 않은 이메일 형식입니다.") | ||
@Schema(description = "이메일", example = "example@gmail.com") | ||
private String email; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/darkoverload/itzip/feature/user/util/PasswordUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package darkoverload.itzip.feature.user.util; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Component | ||
public class PasswordUtil { | ||
|
||
// 사용 가능한 문자 집합 | ||
private static final String LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
private static final String DIGITS = "0123456789"; | ||
private static final String SPECIALS = "!@#$%^&*?_"; | ||
|
||
private static final SecureRandom random = new SecureRandom(); | ||
|
||
/** | ||
* 주어진 정규식 조건을 만족하는 랜덤 비밀번호를 생성 | ||
* 정규식: ^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!@#$%^&*?_]).{8,16}$ | ||
* | ||
* @return 조건에 맞는 랜덤 비밀번호 | ||
*/ | ||
public static String generatePassword() { | ||
// 비밀번호 길이를 8~16 사이로 랜덤 선택 | ||
int passwordLength = 8 + random.nextInt(9); // 8 ~ 16 | ||
|
||
List<Character> passwordChars = new ArrayList<>(); | ||
|
||
// 각 그룹에서 최소 1개씩 추가하여 정규식 조건 만족 | ||
passwordChars.add(LETTERS.charAt(random.nextInt(LETTERS.length()))); | ||
passwordChars.add(DIGITS.charAt(random.nextInt(DIGITS.length()))); | ||
passwordChars.add(SPECIALS.charAt(random.nextInt(SPECIALS.length()))); | ||
|
||
// 남은 길이만큼 임의의 문자 추가 | ||
String allAllowed = LETTERS + DIGITS + SPECIALS; | ||
for (int i = 3; i < passwordLength; i++) { | ||
passwordChars.add(allAllowed.charAt(random.nextInt(allAllowed.length()))); | ||
} | ||
|
||
// 문자 순서를 섞어서 예측 불가하게 만듦 | ||
Collections.shuffle(passwordChars, random); | ||
|
||
// List<Character>를 String으로 변환 | ||
StringBuilder password = new StringBuilder(); | ||
for (Character ch : passwordChars) { | ||
password.append(ch); | ||
} | ||
|
||
return password.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.