Example #1
0
        /// <summary>
        /// Receives an HTTP request and check if it contains login details and if these details are correct
        /// </summary>
        /// <param name="headers">HTTP request splitted to rows</param>
        /// <returns>True if login details are exist and correct</returns>
        public bool authenticate(string[] headers)
        {
            bool auth = false;

            string[] temp;
            string   basic;

            foreach (string header in headers)
            {
                if (header.ToLower().IndexOf("authorization") >= 0)
                {
                    temp  = header.Split(' ');
                    basic = temp[temp.Length - 1].Trim();

                    byte[] decbasic      = Convert.FromBase64String(basic);
                    string decodedString = Encoding.UTF8.GetString(decbasic);

                    if (decodedString.Equals(PermanentData.auth()))
                    {
                        auth = true;
                    }
                }
            }
            return(auth);
        }