import [Link].
JOptionPane;
import [Link];
public class UserAccountSystem {
public static void main(String[] args) {
signUp();
}
static void signUp() {
String inputName = getUserInput("Enter Username:");
String inputPassword = getUserInput("Enter Password:");
setUserName(inputName);
setPassword(inputPassword);
generateOTP();
displayMessage("An OTP has been sent: " + getOtpCode());
verifyOTP();
}
static void verifyOTP() {
String inputOtp = getUserInput("Enter OTP to verify:");
if ([Link](getOtpCode())) {
displayMessage("Account successfully created!");
login();
} else {
displayMessage("Invalid OTP. Try again.");
verifyOTP();
}
}
static void login() {
if (getLoggedIn()) {
displayMessage("Already logged in.");
logout();
} else {
String inputName = getUserInput("Enter Username to login:");
String inputPassword = getUserInput("Enter Password:");
if ([Link](getUserName()) &&
[Link](getPassword())) {
setLoggedIn(true);
displayMessage("Login successful!");
logout();
} else {
displayMessage("Username or Password is incorrect.");
login();
}
}
}
static void logout() {
String choice = getUserInput("Enter your password to logout or type 'OTP'
for OTP logout:");
if ([Link](getPassword())) {
setLoggedIn(false);
displayMessage("Logged out successfully!");
[Link](0); // Exit the program
} else if ([Link]("OTP")) {
String inputOtp = getUserInput("Enter OTP for logout:");
if ([Link](getOtpCode())) {
setLoggedIn(false);
displayMessage("Logged out using OTP!");
[Link](0); // Exit the program
} else {
displayMessage("Invalid OTP.");
logout();
}
} else {
displayMessage("Invalid password.");
logout();
}
}
static String getUserInput(String message) {
return [Link](message);
}
static void setUserName(String userName) {
[Link](userName);
}
static String getUserName() {
return [Link]();
}
static void setPassword(String password) {
[Link](password);
}
static String getPassword() {
return [Link]();
}
static void generateOTP() {
Random random = new Random();
int otp = [Link](10000);
setOtpCode([Link]("%04d", otp));
}
static void setOtpCode(String otp) {
[Link](otp);
}
static String getOtpCode() {
return [Link]();
}
static void setLoggedIn(boolean loggedIn) {
[Link](loggedIn);
}
static boolean getLoggedIn() {
return [Link]();
}
static void displayMessage(String message) {
[Link](null, message);
}
}
class UserAccount {
static String userName = "";
static String password = "";
static String otpCode = "";
static boolean loggedIn = false;
static void setUserName(String userName) {
[Link] = userName;
}
static String getUserName() {
return userName;
}
static void setPassword(String password) {
[Link] = password;
}
static String getPassword() {
return password;
}
static void setOtpCode(String otpCode) {
[Link] = otpCode;
}
static String getOtpCode() {
return otpCode;
}
static void setLoggedIn(boolean loggedIn) {
[Link] = loggedIn;
}
static boolean getLoggedIn() {
return loggedIn;
}
}