hacker_yusu

loginValidation

Jul 14th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.55 KB | None | 0 0
  1. public void loginValidation(){
  2.   String str1 = user.getText();
  3.      char[] pwd = pass.getPassword();
  4. String s = new String(pwd);  //converting char to string
  5. String p = s;
  6.      
  7.         if("".equals(str1)){
  8.        JOptionPane.showMessageDialog(null, "User Name is Empty", "Login Status", JOptionPane.ERROR_MESSAGE);  
  9.      }
  10.         else if((p.length()) == 0)
  11.           {
  12. JOptionPane.showMessageDialog(null, "Password is Empty", "Login Status", JOptionPane.ERROR_MESSAGE);
  13.             }
  14. else{
  15.             try{
  16.             Class.forName("com.mysql.jdbc.Driver");
  17.             Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hotel","root","root");
  18.             Statement stmt=con.createStatement();
  19.             ResultSet rs=stmt.executeQuery("SELECT * FROM details WHERE USER='" + str1 +"' and PASSWORD='" + p + "'");
  20.             if (rs.next()) {
  21.                 this.dispose();
  22.                 s1=rs.getString(1);
  23.                 f_user=s1;
  24.                 s2=rs.getString(2);
  25.                 s3=rs.getString(3);
  26.                 s4=rs.getString(4);
  27.                 s5=rs.getString(5);
  28.                 s6=rs.getString(6);
  29.                 JOptionPane.showMessageDialog(null, "Login Successfull", "Login Status", JOptionPane.INFORMATION_MESSAGE);
  30.                         if (rs.getString(7).equals("admin"))
  31.                         {
  32.                             this.setVisible(false);
  33.                             this.dispose();
  34.                             Admin frm = new Admin();
  35.                             frm.setVisible(true);
  36.                         }
  37.                         else if (rs.getString(7).equals("customer"))
  38.                         {
  39.                             this.setVisible(false);
  40.                             this.dispose();
  41.                             Customer cus = new Customer();
  42.                             cus.setVisible(true);
  43.                         }
  44.                         else
  45.                         {
  46.                             this.setVisible(false);
  47.                             this.dispose();
  48.                             Employee emp = new Employee();
  49.                             emp.setVisible(true);
  50.                         }
  51.             }
  52.                         else{      
  53.                         JOptionPane.showMessageDialog(null,"Invalid username or password","Invalid",JOptionPane.ERROR_MESSAGE);
  54.                     }con.close();
  55.                    
  56.            
  57.         }catch(Exception e)
  58.         {
  59.             System.out.println(e);
  60.         }
  61.        
  62.      }
  63. }
Add Comment
Please, Sign In to add comment