What I need to do is to prompt the user with a username and password (authentication is done locally) and if it checks out, the user would then be able to access the main program body.
public static void main(String[] args){
//String input = JOptionPane.showInputDialog("Enter password to continue: ");
//input2 = Integer.parseInt(input);
// followed by the creation of the main frame
new Cashier3();
Cashier3 frame = new Cashier3();
frame.setTitle("CASHIER 2");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
is there any quick way to go about doing this?
You can use showInputDialog to get the user name
and the below code to get the password
JLabel label = new JLabel("Please enter your password:");
JPasswordField jpf = new JPasswordField();
JOptionPane.showConfirmDialog(null,
new Object[]{label, jpf}, "Password:",
JOptionPane.OK_CANCEL_OPTION);
and write a if condition to check the user name and password
if (!isValidLogin()){
//You can give some message here for the user
System.exit(0);
}
// If login is validated, then the user program will proceed further
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With