-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOTPGenerator.java
More file actions
31 lines (25 loc) · 925 Bytes
/
Copy pathOTPGenerator.java
File metadata and controls
31 lines (25 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.orderservice.ctrl;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
public class OTPGenerator {
private static final int MIN_OTP_VALUE = 1000;
private static final int MAX_OTP_VALUE = 9999;
private static final SecureRandom secureRandom;
static {
SecureRandom tempSecureRandom = null;
try {
tempSecureRandom = SecureRandom.getInstanceStrong();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
// Handle exception as appropriate
}
secureRandom = tempSecureRandom;
}
public static int generateOTP() {
return secureRandom.nextInt(MAX_OTP_VALUE - MIN_OTP_VALUE + 1) + MIN_OTP_VALUE;
}
public static void main(String[] args) {
int otp = generateOTP();
System.out.println("Generated OTP: " + otp);
}
}