private session getSession(string hash, string ip, string useragent)
        {
            session returnme = null;

            String dbConnectionString = ConfigurationManager.ConnectionStrings["SchoolLogicDatabase"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(dbConnectionString))
            {
                returnme = session.loadThisSession(connection, hash, ip, useragent);
            }

            if (returnme != null)
            {
                if (returnme.getIP().Equals(ip))
                {
                    if (returnme.getUserAgent().Equals(useragent))
                    {
                        if (returnme.getStart() < DateTime.Now)
                        {
                            if (returnme.getEnd() > DateTime.Now)
                            {
                                return(returnme);
                            }
                        }
                    }
                }
            }

            return(null);
        }
        protected void btnKey_Click(object sender, EventArgs e)
        {
            String  dbConnectionString = ConfigurationManager.ConnectionStrings["DataExplorerDatabase"].ConnectionString;
            session loggedInUser       = null;

            /* Validate the description */
            string newDescription = txtDescription.Text;

            if (newDescription.Length > 0)
            {
                using (SqlConnection connection = new SqlConnection(dbConnectionString))
                {
                    loggedInUser = session.loadThisSession(connection, getSessionIDFromCookies(), Request.ServerVariables["REMOTE_ADDR"], Request.ServerVariables["HTTP_USER_AGENT"]);

                    if (loggedInUser != null)
                    {
                        APIKey.createAPIKey(connection, loggedInUser.getUsername(), false, newDescription, Request.ServerVariables["ALL_RAW"] + DateTime.Now + loggedInUser.getUsername() + loggedInUser.getIP());
                        refreshKeyList();
                        txtDescription.Text = "Enter a description here";
                    }
                }
            }
        }