Ejemplo n.º 1
0
        /// <summary>
        /// Validate client credential with MembershipProvider
        /// </summary>
        /// <param name="providerName"></param>
        /// <param name="credential"></param>
        /// <returns></returns>
        private static bool MembershipAuthenticate(string providerName, UserCredential credential)
        {
            var provider = Membership.Providers[providerName];
            if (provider == null)
                throw new Exception("Membership Provider not found");

            return provider.ValidateUser(credential.Username, credential.Password);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validate client credential with UserNamePasswordValidator
        /// </summary>
        /// <param name="validatorType"></param>
        /// <param name="credential"></param>
        /// <returns></returns>
        private static bool ValidatorAuthenticate(Type validatorType, UserCredential credential)
        {
            if (validatorType == null)
                throw new Exception("Custom validator is not set");
            if (!typeof(UserNamePasswordValidator).IsAssignableFrom(validatorType))
                throw new Exception(
                    "Validator type must be derived class of System.IdentityModel.Selectors.UserNamePasswordValidator");
            var validator = Activator.CreateInstance(validatorType) as UserNamePasswordValidator;

            if (validator != null) validator.Validate(credential.Username, credential.Password);
            return true;
        }