×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Israel Edet
Added: Jan 4, 2017 10:03 PM
Views: 2189
Tags: no tags
  1.  
  2. package inventorysystem.data;
  3.  
  4. import java.sql.ResultSet;
  5. import java.sql.Statement;
  6. import javax.swing.JPanel;
  7. import interfaces.Switchable;
  8.  
  9. /**
  10.  *Login Class to login user into system
  11.  * @author Epic
  12.  */
  13. public class Login {
  14.     private DBConnectionClass connectionClass;
  15.     public Login(){
  16.         connectionClass = new DBConnectionClass();
  17.     }
  18.     /**
  19.      * if user credential is a valid one then return an
  20.      * employee object for that user.
  21.      * @param username
  22.      * @param password
  23.      * @param panelSwitch if login is sucessfully then switch to next panel
  24.      * @return Employee object
  25.      */
  26.     public  Employee isUser(String username, String password){
  27.        
  28.         Employee employee = null;
  29.         try {
  30.             Statement s = this.connectionClass.getConnection().createStatement();
  31.             ResultSet rs = s.executeQuery("SELECT * FROM employees WHERE username = '"+username+"' AND password = '"+password+"'");
  32.             if(rs.first()){
  33.                 employee =  new Employee(rs.getString("first_name").concat(" ").concat(rs.getString("last_name")),
  34.                         rs.getString("username"),
  35.                         rs.getInt("employee_id"),
  36.                         rs.getString("gender"),
  37.                         rs.getString("birth_date"),
  38.                         rs.getString("address"));
  39.                
  40.             }
  41.         } catch (Exception e) {
  42.             e.printStackTrace();
  43.         }
  44.         return employee;
  45.     }
  46.    
  47. }
  48.