protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        HttpSession session = null;
        request.setCharacterEncoding("UTF-8");
        String name = request.getParameter("username");
        String password = request.getParameter("password");
        User user = null;

        if (name == null || name.equals("")) {
            setError("You didn't give a username!", request);
            showJSP("index.jsp", request, response);
            return;
        }

        // sets the new default username as the previously entered username
        request.setAttribute("username", name);

        if (password == null || password.equals("")) {
            setError("You didn't give a password!", request);
            showJSP("index.jsp", request, response);
            return;
        }
        try {
            user = User.getUser(name);
        } catch (SQLException ex) {
            Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            // does the user by that name exist & is the password correct?
            if (user != null && User.validatePassword(password, user.getPassword())) {
                session = request.getSession();
                session.setAttribute("loggedIn", user);
                response.sendRedirect("Games");
            } else {
                setError("Try again! Your username or password was incorrect.", request);
                showJSP("index.jsp", request, response);
            }
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidKeySpecException ex) {
            Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }