Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
add password verifier on homepage pass change
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdcruz committed Dec 8, 2022
1 parent 4cc3b5e commit 77755fe
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/main/java/com/pharmacy/Views/HomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 77755fe

Please sign in to comment.