Esempio n. 1
0
        private void GetPasswordHelper(bool requireQA, bool enablePasswordRetrieval, string answer)
        {
            MembershipCreateStatus status;

            provider = new MySQLMembershipProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("requiresQuestionAndAnswer", requireQA ? "true" : "false");
            config.Add("enablePasswordRetrieval", enablePasswordRetrieval ? "true" : "false");
            config.Add("passwordFormat", "clear");
            config.Add("applicationName", "/");
            config.Add("writeExceptionsToEventLog", "false");
            provider.Initialize(null, config);

            provider.CreateUser("foo", "barbar!", "*****@*****.**", "color", "blue", true, null, out status);

            string password = string.Empty;

            if (!enablePasswordRetrieval)
            {
                if (requireQA && answer != null)
                {
                    Exception ex = Assert.Throws <MembershipPasswordException>(() => provider.GetPassword("foo", answer));
                }
                else
                {
                    Exception ex = Assert.Throws <ProviderException>(() => provider.GetPassword("foo", answer));
                    Assert.Equal(ex.Message, "Password Retrieval Not Enabled.");
                }
            }
            else
            {
                if (requireQA && answer != null)
                {
                    provider.GetPassword("foo", answer);
                }
                else if (requireQA && answer == null)
                {
                    //Incorrect password answer.
                    Assert.Throws <MembershipPasswordException>(() => provider.GetPassword("foo", answer));
                }
                else
                {
                    password = provider.GetPassword("foo", answer);
                    Assert.Equal("barbar!", password);
                }
            }

            //Cleanup
            provider.DeleteUser("foo", true);
        }
Esempio n. 2
0
        public void GetEncryptedPassword()
        {
            MembershipCreateStatus status;

            provider = new MySQLMembershipProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("requiresQuestionAndAnswer", "false");
            config.Add("enablePasswordRetrieval", "true");
            config.Add("passwordFormat", "encrypted");
            config.Add("applicationName", "/");
            provider.Initialize(null, config);

            MembershipUser user = provider.CreateUser("foo", "barbar!", "*****@*****.**", null, null, true, null, out status);

            Assert.NotNull(user);

            string pw = provider.GetPassword("foo", null);

            Assert.Equal("barbar!", pw);

            //Cleanup
            provider.DeleteUser("foo", true);
        }
Esempio n. 3
0
        public void GetPasswordWithWrongAnswer()
        {
            MembershipCreateStatus status;

            provider = new MySQLMembershipProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("requiresQuestionAndAnswer", "true");
            config.Add("enablePasswordRetrieval", "true");
            config.Add("passwordFormat", "Encrypted");
            config.Add("applicationName", "/");
            provider.Initialize(null, config);
            provider.CreateUser("foo", "barbar!", "*****@*****.**", "color", "blue", true, null, out status);

            MySQLMembershipProvider provider2 = new MySQLMembershipProvider();
            NameValueCollection     config2   = new NameValueCollection();

            config2.Add("connectionStringName", "LocalMySqlServer");
            config2.Add("requiresQuestionAndAnswer", "true");
            config2.Add("enablePasswordRetrieval", "true");
            config2.Add("passwordFormat", "Encrypted");
            config2.Add("applicationName", "/");
            provider2.Initialize(null, config2);
            Assert.Throws <MembershipPasswordException>(() => provider2.GetPassword("foo", "wrong"));

            //Cleanup
            provider.DeleteUser("foo", true);
        }
Esempio n. 4
0
        private void GetPasswordHelper(bool requireQA, bool enablePasswordRetrieval, string answer)
        {
            MembershipCreateStatus status;

            provider = new MySQLMembershipProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("requiresQuestionAndAnswer", requireQA ? "true" : "false");
            config.Add("enablePasswordRetrieval", enablePasswordRetrieval ? "true" : "false");
            config.Add("passwordFormat", "clear");
            config.Add("applicationName", "/");
            provider.Initialize(null, config);

            provider.CreateUser("foo", "barbar!", "*****@*****.**", "color", "blue", true, null, out status);

            try
            {
                string password = provider.GetPassword("foo", answer);
                if (!enablePasswordRetrieval)
                {
                    Assert.Fail("This should have thrown an exception");
                }
                Assert.AreEqual("barbar!", password);
            }
            catch (ProviderException)
            {
                if (requireQA && answer != null)
                {
                    Assert.Fail("This should not have thrown an exception");
                }
            }
        }
Esempio n. 5
0
 public void GetPassword()
 {
     provider = new MySQLMembershipProvider();
     NameValueCollection config = new NameValueCollection();
     config.Add("connectionStringName", "LocalMySqlServer");
     config.Add("applicationName", "/");
     config.Add("enablePasswordRetrieval", "true");
     config.Add("passwordFormat", "Clear");
     config.Add("requireQuestionAndAnswer", "false");
     try
     {
         provider.Initialize(null, config);
         MembershipCreateStatus status;
         MembershipUser user = provider.CreateUser("foo", "pass", "*****@*****.**",
             null, null, true, null, out status);
         string password = provider.GetPassword("foo", null);
         Assert.AreEqual("pass", password);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message);
     }
 }