private void logInButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logInButtonActionPerformed
        //hash the password
        //MessageDigest handles hashing in various forms
        MessageDigest md;
        //declare the password hashed string
        String hashedPassword="";
        try {
            //set the hash type to SHA256
            md = MessageDigest.getInstance("SHA-256");
            //retrieve the text from the password field
            String text = passwordTextBox.getText();
            try {
                //encode the hash in UTF8, to match the DB
                md.update(text.getBytes("UTF-8")); 
            } catch (UnsupportedEncodingException e) {
                System.out.println(e);
            }
            //hashed password in raw HEX
            byte[] hashedP = md.digest();
            //convert the raw data to a string, directly comparable to DB string
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < hashedP.length; ++i) {
            sb.append(Integer.toHexString((hashedP[i] & 0xFF) | 0x100).substring(1,3));
            }
            hashedPassword= sb.toString();            
        } catch (NoSuchAlgorithmException ex) {
            System.out.println(ex);
        }
        //end of hashing
        //check credentials with DB
        //get the count that match both stafid(login) and hashed password, should be 1 if valid
        boolean connectSuccess=Helper.openConnection();
        //open the connection to DB, and proceed is succesfull
        if(connectSuccess){
            String SQL="SELECT count(*) AS success, appointment FROM tstaff WHERE staffid='"+userNameTextBox.getText()+"' AND password='"+hashedPassword+"'" ;
            //userNameTextBox.setText(SQL);//DEBUG
            ResultSet rs=Helper.selectFromDatabase(SQL);
            String loginSuccess="0";
            int staffLevel=0;
            try{
                rs.next();
                loginSuccess=rs.getString("success");
                //if they are a sales assistant they are level 1
                //only doing it on success avoids Null exception
                if(loginSuccess.equals("1")){
                    if(rs.getString("appointment").equals("Sales Assistant TGP")){
                        staffLevel=1;
                    }   
                
                //all other jobs are managment and level 2
                //add more cases here if project needs more granular levels
                else{
                    staffLevel=2;
                }
             }
            
                    
            }
            catch(SQLException e){
                // do nothing :)
            }

            //successful login
            if(loginSuccess.equals("1"))
            {
                //summon the main application!
                Application application = new Application(userNameTextBox.getText(),staffLevel,this);        
                application.setVisible(true);
                //clear the username and password fields, so they are blank on next login prompt
                userNameTextBox.setText("");
                passwordTextBox.setText("");
                //hide the failure message,  so it is not visible on next login prompt
                loginFailureLabel.setVisible(false);
                //hide the login prompt
                this.setVisible(false);
            }
            //failure
            else
            {
                //tell the user he failed to login
                loginFailureLabel.setVisible(true);
            }
            //close the connection
            boolean closeSuccess=Helper.closeConnection();
        }
    }//GEN-LAST:event_logInButtonActionPerformed