tot service modify
This commit is contained in:
parent
e00cba6279
commit
40578b2407
|
@ -23,7 +23,7 @@ public class MemberTotpService {
|
||||||
|
|
||||||
public void regist(Member member, String secretCode, String code) throws Exception {
|
public void regist(Member member, String secretCode, String code) throws Exception {
|
||||||
|
|
||||||
if (null == member || 0 < member.getId()) {
|
if (null == member || 0 >= member.getId()) {
|
||||||
throw new Exception("Not Null Member ID");
|
throw new Exception("Not Null Member ID");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,8 @@ public class MemberTotpService {
|
||||||
|
|
||||||
public boolean checkCode(String secretCode, String code) throws Exception {
|
public boolean checkCode(String secretCode, String code) throws Exception {
|
||||||
GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator();
|
GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator();
|
||||||
boolean isCheck = googleAuthenticator.authorize(secretCode, Integer.valueOf(code));
|
int codeInt = Integer.parseInt(code);
|
||||||
|
boolean isCheck = googleAuthenticator.authorize(secretCode, codeInt);
|
||||||
|
|
||||||
if (!isCheck) {
|
if (!isCheck) {
|
||||||
throw new Exception("Invalid Code");
|
throw new Exception("Invalid Code");
|
||||||
|
|
|
@ -11,6 +11,8 @@ import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,7 +48,7 @@ public class MemberTotpServiceTest {
|
||||||
MemberTotp totp = new MemberTotp();
|
MemberTotp totp = new MemberTotp();
|
||||||
totp.setSecretCode("PN44SRPS5QCGCJNS");
|
totp.setSecretCode("PN44SRPS5QCGCJNS");
|
||||||
|
|
||||||
boolean isCheck = this.totpService.checkCode(totp, "125073");
|
boolean isCheck = this.totpService.checkCode("PN44SRPS5QCGCJNS", "125073");
|
||||||
|
|
||||||
System.out.println(isCheck);
|
System.out.println(isCheck);
|
||||||
|
|
||||||
|
@ -57,10 +59,10 @@ public class MemberTotpServiceTest {
|
||||||
|
|
||||||
Member m = new Member(2);
|
Member m = new Member(2);
|
||||||
m.setEmail("geekdev@naver.com");
|
m.setEmail("geekdev@naver.com");
|
||||||
MemberTotp totp = this.totpService.createTotp(m);
|
Map<String, String> totp = this.totpService.createTotp(m );
|
||||||
|
|
||||||
System.out.println(totp.getSecretCode());
|
System.out.println(totp.get("key"));
|
||||||
System.out.println(totp.getOtpAuth());
|
System.out.println(totp.get("uri"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user