示例#1
0
        internal IPrincipal ParseBasicAuthentication(string authData)
        {
            try {
                // HTTP Basic Authentication data is a formatted Base64 string.
                var authString = Encoding.Default.GetString(Convert.FromBase64String(authData));

                // The format is domain\username:password.
                // Domain is optional.

                var pos      = authString.IndexOf(':');
                var user     = authString.Substring(0, pos);
                var password = authString.Substring(pos + 1);

                // Check if there is a domain.
                pos = user.IndexOf('\\');
                if (pos > 0)
                {
                    user = user.Substring(pos + 1);
                }

                var identity = new System.Net.HttpListenerBasicIdentity(user, password);
                // TODO: What are the roles MS sets?
                return(new GenericPrincipal(identity, new string [0]));
            } catch {
                return(null);
            }
        }
示例#2
0
        internal IPrincipal ParseBasicAuthentication(string authData)
        {
            try {
                // Basic AUTH Data is a formatted Base64 String
                //string domain = null;
                string user       = null;
                string password   = null;
                int    pos        = -1;
                string authString = Encoding.Default.GetString(Convert.FromBase64String(authData));

                // The format is DOMAIN\username:password
                // Domain is optional

                pos = authString.IndexOf(':');

                // parse the password off the end
                password = authString.Substring(pos + 1);

                // discard the password
                authString = authString.Substring(0, pos);

                // check if there is a domain
                pos = authString.IndexOf('\\');

                if (pos > 0)
                {
                    //domain = authString.Substring (0, pos);
                    user = authString.Substring(pos);
                }
                else
                {
                    user = authString;
                }

                var identity = new System.Net.HttpListenerBasicIdentity(user, password);
                // TODO: What are the roles MS sets
                return(new GenericPrincipal(identity, new string [0]));
            } catch (Exception) {
                // Invalid auth data is swallowed silently
                return(null);
            }
        }
        internal IPrincipal ParseBasicAuthentication(string authData)
        {
            try {
                // HTTP Basic Authentication data is a formatted Base64 string.
                var authString = Encoding.Default.GetString (Convert.FromBase64String (authData));

                // The format is domain\username:password.
                // Domain is optional.

                var pos = authString.IndexOf (':');
                var user = authString.Substring (0, pos);
                var password = authString.Substring (pos + 1);

                // Check if there is a domain.
                pos = user.IndexOf ('\\');
                if (pos > 0)
                    user = user.Substring (pos + 1);

                var identity = new System.Net.HttpListenerBasicIdentity (user, password);
                // TODO: What are the roles MS sets?
                return new GenericPrincipal (identity, new string [0]);
            } catch {
                return null;
            }
        }
        internal IPrincipal ParseBasicAuthentication(string authData)
        {
            try {
                // Basic AUTH Data is a formatted Base64 String
                //string domain = null;
                string user       = null;
                string password   = null;
                int    pos        = -1;
                string authString = Encoding.Default.GetString (Convert.FromBase64String (authData));

                // The format is DOMAIN\username:password
                // Domain is optional

                pos = authString.IndexOf (':');

                // parse the password off the end
                password = authString.Substring (pos+1);

                // discard the password
                authString = authString.Substring (0, pos);

                // check if there is a domain
                pos = authString.IndexOf ('\\');

                if (pos > 0) {
                    //domain = authString.Substring (0, pos);
                    user = authString.Substring (pos);
                } else {
                    user = authString;
                }

                var identity = new System.Net.HttpListenerBasicIdentity (user, password);
                // TODO: What are the roles MS sets
                return new GenericPrincipal (identity, new string [0]);
            } catch (Exception) {
                // Invalid auth data is swallowed silently
                return null;
            }
        }