Guest User

Untitled

a guest
Jan 6th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. private void loginDatabase(){
  2. //Checks to see if Login is Administrator and then sends him to his respective location
  3.  
  4. String userName1 = Usr1.getText();
  5. String passWord1 = Pass1.getText();
  6.  
  7. try{
  8. String query1 = "select * from LoginManager where Username='"+userName1+"' and Password='"+passWord1+"' and Position=?";
  9. PreparedStatement pst1 = conn.prepareStatement(query1);
  10. ResultSet rs1 = pst1.executeQuery();
  11.  
  12. if (rs1.next()){
  13.  
  14. String add1 = rs1.getString("Username");
  15. usernameCon1.setText(add1);
  16.  
  17. String add2 = rs1.getString("Password");
  18. passwordCon1.setText(add2);
  19.  
  20. String add3 = rs1.getString("Position");
  21. positionCon1.setText(add3);
  22.  
  23. }
  24.  
  25. pst1.close();
  26. rs1.close();
  27.  
  28. }catch(Exception e){
  29. JOptionPane.showMessageDialog(null, e);
  30. }
  31.  
  32. }
  33.  
  34. private void login(){
  35.  
  36. loginDatabase();
  37.  
  38. if (usernameCon1.getText().matches(regex) &&passwordCon1.getText().matches(Pass1.getText()) && positionCon1.getText().equals("Administrator")){
  39.  
  40. Admin();
  41. usernameCon1.setText("");
  42. passwordCon1.setText("");
  43. positionCon1.setText("");
  44. Usr1.setText("");
  45. Pass1.setText("");
  46.  
  47. }
  48.  
  49. else if (!usernameCon1.getText().isEmpty() && !passwordCon1.getText().isEmpty() && positionCon1.getText().equals("Manager")){
  50.  
  51.  
  52.  
  53. }
  54.  
  55. else if (!usernameCon1.getText().isEmpty() && !passwordCon1.getText().isEmpty() && positionCon1.getText().equals("Teacher")){
  56.  
  57.  
  58.  
  59. }
  60.  
  61. else {
  62.  
  63. JOptionPane.showMessageDialog(null, "Invalid Login", "Invalid Login", JOptionPane.ERROR_MESSAGE);
  64.  
  65. }
  66.  
  67. }
Add Comment
Please, Sign In to add comment