Question: I created a GUI Login App where a password when submitted it is inputted into a log.txt file. The log should include the username, the
I created a GUI Login App where a password when submitted it is inputted into a log.txt file. The log should include the username, the date, the time and if the login was successful or not. Can you help with the Java code? I have hard coded a password, which it works and the JOption Message success works then right after the JOption Message invalid password message pops up that is at the bottom of the code where the if(valid). I'm not sure how to code the following if to show an invalid password then have the JOption Message appear with invalid message.
private void LogsubmitActionPerformed(java.awt.event.ActionEvent evt) { try{ String password = jPassword.getText(); String username = jtxtUsername.getText(); File texting = new File("Log.txt"); //open file in append mode BufferedWriter writer; writer = new BufferedWriter(new FileWriter(texting,true)); Date currentTime =Calendar.getInstance().getTime(); boolean valid = false; if(password.equals("letmein")&&(username.equals("deanna"))); { jtxtUsername.setText(null); jPassword.setText(null); } JOptionPane.showMessageDialog(null, "success"); writer.write(username + currentTime); writer.write("success"); if(valid); JOptionPane.showMessageDialog(null, "invalid password"); writer.write("failed"); writer.close(); } catch (IOException ex) { Logger.getLogger(LoginApp.class.getName()).log(Level.SEVERE, null, ex); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
