Skip to content
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
merged 2 commits into from
Jan 7, 2024
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
@@ -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;
Copy link
Member

Choose a reason for hiding this comment

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

p5:
사소한 궁금한점이 생겼는데 상수값 사이에 있는 _은 뭘까요..? STARTNUM이 실수 값으로 어디서부터 되는걸까요..?

Copy link
Member Author

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이 들어갑니다.

Copy link
Member Author

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 이런 식으로도 할 수 있는데 너무 단편적으로 생각했네요...!
이 점은 후순위로 수정하겠습니다..!

private static final int END_NUM = 999_999;

public static String generate() {
return String.valueOf(secureRandom.nextInt(START_NUM, END_NUM));
}
}
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);
}
}