Exemplo n.º 1
0
        /// <summary>
        /// Check if the user has already logged in
        /// </summary>
        /// <returns>username string if success, otherwise null</returns>
        private static string GetLoggedInUsername()
        {
            // first check if 'username' variable is in session
            if (HttpContext.Current.Session[UsernameAccessString] != null)
            {
                string username = (string)HttpContext.Current.Session[UsernameAccessString];

                // now check for the 'username' in the database for additional check
                DataTable loginUserTable = DataAccessLayer.SelectCommand(DataAccessLayer.SelectCommandString(
                                                                             "Username", LoginTable, "Username = :username"),
                                                                         new CommandParameter(":username", username));

                if (1 == loginUserTable.Rows.Count)
                {
                    return(username);
                }
                // clear session state because it is not available in the database
                HttpContext.Current.Session.Clear();
                CurrentInstance.Reset();
            }
            return(null);
        }