-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#20 [feat] 6자리 암호 코드 생성 구현 #22
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/main/java/com/moddy/server/common/util/VerificationCodeGenerator.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,13 @@ | ||
package com.moddy.server.common.util; | ||
|
||
import java.security.SecureRandom; | ||
|
||
public class VerificationCodeGenerator { | ||
private static final SecureRandom secureRandom = new SecureRandom(); | ||
private static final int START_NUM = 100_000; | ||
private static final int END_NUM = 999_999; | ||
|
||
public static String generate() { | ||
return String.valueOf(secureRandom.nextInt(START_NUM, END_NUM)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/com/moddy/server/common/util/VerificationCodeGeneratorTest.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,21 @@ | ||
package com.moddy.server.common.util; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
|
||
public class VerificationCodeGeneratorTest { | ||
|
||
@Test | ||
@DisplayName("인증 코드는 항상 6자리이다.") | ||
void generateTest() { | ||
// given | ||
|
||
// when | ||
String result = VerificationCodeGenerator.generate(); | ||
// then | ||
assertThat(result.length()).isEqualTo(6); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p5:
사소한 궁금한점이 생겼는데 상수값 사이에 있는 _은 뭘까요..? STARTNUM이 실수 값으로 어디서부터 되는걸까요..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hellozo0
저희가 돈 계산할 때 1,000 이런 식으로 표현하는데, 자바에서
_
을 사용해서 000 단위를 분리할 수 있습니다.100000 -> 10_000
이를 통해 숫자 가독성을 높일 수 있고, 들어가는 값은 똑같이 100000이 들어갑니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6자리 숫자를 넘기기 때문에
100,000 ~ 999,999 사이의 값을 반환하고 있습니다.,,!
근데 생각해보니 095843 이런 식으로도 할 수 있는데 너무 단편적으로 생각했네요...!
이 점은 후순위로 수정하겠습니다..!