public static UserBean login(UserBean bean) {
	
    //preparing some objects for connection 
        Statement stmt = null;    
	
        String username = bean.getUsername();    
        String password = bean.getPassword();
        String role = bean.getRole();
	String searchQuery1 ="select * from user_login where Username='"
                        + username
                        + "' AND Password=ENCODE('"+password+"','helloworld')";
	String searchQuery2 = "select FirstName,LastName from user_info where Username='"+username+"'";   
        // "System.out.println" prints in the console; Normally used to trace the process
        System.out.println("Your user name is " + username);          
        System.out.println("Your password is " + password);
        System.out.println("Query: "+searchQuery1);

        try 
        {
            //connect to DB 
            currentCon = ConnectionManager.getConnection();
            stmt=currentCon.createStatement();
            rs = stmt.executeQuery(searchQuery1);	        
            boolean more = rs.next();
            // if user does not exist set the isValid variable to false
            if (!more) 
            {   
                System.out.println("Sorry, you are not a registered user! Please sign up first");
                bean.setValid(false);
                bean.setRole(rs.getString("role"));
            } 

            //if user exists set the isValid variable to true
            else if (more) 
            {
                rs = stmt.executeQuery(searchQuery2);
                rs.next();
                System.out.println("Welcome ");
                bean.setValid(true);
            }
        } 

        catch (Exception ex) 
        {
            System.out.println("Log In failed: An Exception has occurred! " + ex);
        } 

        //some exception handling
        finally 
        {
            if (rs != null)	{
                try {
                rs.close();
                } catch (Exception e) {}
                rs = null;
                }

            if (stmt != null) {
                try {
                stmt.close();
                } catch (Exception e) {}
                stmt = null;
                }

            if (currentCon != null) {
                try {
                currentCon.close();
                } catch (Exception e) {
                }

                currentCon = null;
            }
        }

        return bean;
    }