From 77755fece30fb2db26104895d10c0cdb5c7b6269 Mon Sep 17 00:00:00 2001 From: jhdcruz Date: Thu, 8 Dec 2022 17:00:59 +0800 Subject: [PATCH] add password verifier on homepage pass change --- .../java/com/pharmacy/Views/HomePage.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/pharmacy/Views/HomePage.java b/src/main/java/com/pharmacy/Views/HomePage.java index 1173b96..053e0bc 100644 --- a/src/main/java/com/pharmacy/Views/HomePage.java +++ b/src/main/java/com/pharmacy/Views/HomePage.java @@ -4,6 +4,7 @@ import com.pharmacy.Models.UserModel; import javax.swing.JOptionPane; +import java.awt.Cursor; import java.awt.EventQueue; import java.sql.ResultSet; import java.text.SimpleDateFormat; @@ -202,16 +203,30 @@ private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN- }//GEN-LAST:event_updateButtonActionPerformed private void changePasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changePasswordActionPerformed - // get current username from selected row - // change password prompt - String password = JOptionPane.showInputDialog(this, "Enter new password for " + username + ":", "Change Password", JOptionPane.PLAIN_MESSAGE); + String verify = JOptionPane.showInputDialog(this, "Enter current password for " + username + ":", "Change Password", JOptionPane.PLAIN_MESSAGE); - if (password != null) { - EventQueue.invokeLater(() -> { - new UserController().updatePass(username, password); - JOptionPane.showMessageDialog(this, "Password changed successfully.", "Success", JOptionPane.INFORMATION_MESSAGE); - }); - } + EventQueue.invokeLater(() -> { + // wait cursor + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + + if (verify != null) { + String password = String.valueOf(new UserController().getPassword(username, verify)); + + if (password.equals(verify)) { + String newPassword = JOptionPane.showInputDialog(this, "Enter new password for " + username + ":", "Change Password", JOptionPane.PLAIN_MESSAGE); + + if (newPassword != null) { + new UserController().updatePass(username, password); + JOptionPane.showMessageDialog(this, "Password changed successfully.", "Success", JOptionPane.INFORMATION_MESSAGE); + } + } else { + JOptionPane.showMessageDialog(this, "Incorrect password.", "Error", JOptionPane.ERROR_MESSAGE); + } + } + + // revert cursor + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + }); }//GEN-LAST:event_changePasswordActionPerformed private void getUser() {