예제 #1
0
        public void Add_ProviderBase()
        {
            TestProviderBase             pb  = new TestProviderBase();
            MembershipProviderCollection mpc = new MembershipProviderCollection();

            mpc.Add(pb);
            // Add accept ProviderBase but docs says it throws
            // an exception if it's not a MembershipProvider
        }
예제 #2
0
        public Provider()
        {
            try
            {
                SqlMembershipProvider sqlMembershipProvider = new SqlMembershipProvider();
                NameValueCollection   config = new NameValueCollection();
                config.Add("connectionStringName", "myConnection");
                config.Add("enablePasswordRetrieval", "false");
                config.Add("enablePasswordReset", "true");
                config.Add("requiresQuestionAndAnswer", "false");
                config.Add("applicationName", "MyApp");
                config.Add("requiresUniqueEmail", "true");
                config.Add("maxInvalidPasswordAttempts", "3");
                config.Add("passwordAttemptWindow", "5");
                config.Add("commandTimeout", "30");
                config.Add("name", "AspNetSqlMembershipProvider");
                config.Add("minRequiredPasswordLength", "9");
                config.Add("minRequiredNonalphanumericCharacters", "1");
                sqlMembershipProvider.Initialize(config["name"], config);

                MembershipProviderCollection membershipProviders = new MembershipProviderCollection();
                membershipProviders.Add(sqlMembershipProvider);
                membershipProviders.SetReadOnly();

                BindingFlags bindingFlags   = BindingFlags.NonPublic | BindingFlags.Static;
                Type         membershipType = typeof(Membership);
                membershipType.GetField("s_Initialized", bindingFlags).SetValue(null, true);
                membershipType.GetField("s_InitializeException", bindingFlags).SetValue(null, null);
                membershipType.GetField("s_HashAlgorithmType", bindingFlags).SetValue(null, "SHA-512");
                membershipType.GetField("s_HashAlgorithmFromConfig", bindingFlags).SetValue(null, false);
                membershipType.GetField("s_UserIsOnlineTimeWindow", bindingFlags).SetValue(null, 15);
                membershipType.GetField("s_Provider", bindingFlags).SetValue(null, sqlMembershipProvider);
                membershipType.GetField("s_Providers", bindingFlags).SetValue(null, membershipProviders);

                var connectionString = Membership.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
                if (connectionString != null)
                {
                    connectionString.SetValue(Membership.Provider, DBCommands._Connection);
                }

                NewPasswordNeeded();
            }
            catch (Exception ex)
            {
                DBCommands.RecordError(ex);
            }
        }
        public void InjectMembershipImplementation(IEnumerable <KeyValuePair <string, string> > simulatedAppConfigSettings)
        {
            if (MembershipIsInitialized)
            {
                _originalProvider = MembershipProvider;
            }
            else
            {
                _originalProvider = null;
            }

            _injectedProvider = GetProvider();

            InitializeMembershipProviderFromConfigEntry(_injectedProvider, simulatedAppConfigSettings);

            PostInitializeUpdate(_injectedProvider);

            MembershipProvider      = _injectedProvider;
            MembershipIsInitialized = true;

            MembershipProviders = new MembershipProviderCollection();
            MembershipProviders.Add(_injectedProvider);
            MembershipProviders.SetReadOnly();
        }
예제 #4
0
        public void Add_Null()
        {
            MembershipProviderCollection mpc = new MembershipProviderCollection();

            mpc.Add(null);
        }