예제 #1
0
        /// <summary>
        /// Retrieves a user from the store.
        /// </summary>
        /// <param name="identifier"></param>
        /// <returns></returns>
        public override IAuthentication RetrieveUser(string identifier)
        {
            IAuthentication setting = null;

            if (!string.IsNullOrEmpty(identifier))
            {
                // If initialised then use the loaded dictionaries
                if (isInitialised)
                {
                    identifier = identifier.ToLower(CultureInfo.InvariantCulture);

                    if ((setting == null) && (loadedUsers.ContainsKey(identifier)))
                    {
                        setting = loadedUsers[identifier];
                    }

                    if (setting == null)
                    {
                        // Attempt to find a matching wild-card
                        foreach (IAuthentication wildCard in wildCardUsers)
                        {
                            if (SecurityHelpers.IsWildCardMatch(wildCard.Identifier, identifier))
                            {
                                setting = wildCard;
                                break;
                            }
                        }
                    }
                }
            }
            return(setting);
        }
예제 #2
0
        /// <summary>
        /// Attempts to authenticate a user from the credentials.
        /// </summary>
        /// <param name="credentials">The credentials.</param>
        /// <returns>True if the credentials are valid, false otherwise.</returns>
        public bool Authenticate(LoginRequest credentials)
        {
            // Check that the user name matches
            string userName = GetUserName(credentials);
            bool   isValid  = !string.IsNullOrEmpty(userName);

            if (isValid)
            {
                isValid = SecurityHelpers.IsWildCardMatch(this.userName, userName);
            }
            return(isValid);
        }
        /// <summary>
        /// Attempts to authenticate a user from the credentials.
        /// </summary>
        /// <param name="credentials">The credentials.</param>
        /// <returns>True if the credentials are valid, false otherwise..</returns>
        public bool Authenticate(LoginRequest credentials)
        {
            // Check that both the user name and the password match
            string userName = GetUserName(credentials);
            string password = NameValuePair.FindNamedValue(credentials.Credentials,
                                                           LoginRequest.PasswordCredential);
            bool isValid = !string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password);

            if (isValid)
            {
                isValid = SecurityHelpers.IsWildCardMatch(userName, this.userName) &&
                          string.Equals(password, this.password, StringComparison.InvariantCulture);
            }
            return(isValid);
        }