public static UserToken GetToken(string userName)
        {
            SiteSecurityConfig ssc = GetSecurity();

            foreach (User user in ssc.Users)
            {
                if (user.Name.ToUpper() == userName.ToUpper())
                {
                    return(user.ToToken());
                }
            }
            return(null);
        }
        public static UserToken Login(string userName, string password)
        {
            SiteSecurityConfig ssc = GetSecurity();

            foreach (User user in ssc.Users)
            {
                if (user.Name.ToUpper() == userName.ToUpper())
                {
                    if (user.Password == password)
                    {
                        return(user.ToToken());
                    }
                }
            }
            return(null);
        }
        public static void AddUser(string userName, string password, string role)
        {
            SiteSecurityConfig ssc = GetSecurity();
            User user = new User();

            user.Name     = userName;
            user.Password = password;
            user.Role     = role;
            ssc.Users.Add(user);

            XmlSerializer ser = new XmlSerializer(typeof(SiteSecurityConfig));

            using (StreamWriter writer = new StreamWriter(HttpContext.Current.Server.MapPath("SiteConfig/siteSecurity.config")))
            {
                ser.Serialize(writer, ssc);
            }
        }
        public static SiteSecurityConfig GetSecurity()
        {
            XmlSerializer      ser = new XmlSerializer(typeof(SiteSecurityConfig));
            SiteSecurityConfig value;

            string fullPath = HttpContext.Current.Server.MapPath("SiteConfig/siteSecurity.config");

            if (File.Exists(fullPath))
            {
                using (StreamReader reader = new StreamReader(fullPath))
                {
                    value = (SiteSecurityConfig)ser.Deserialize(reader);
                }
            }
            else
            {
                value = new SiteSecurityConfig();
            }
            return(value);
        }