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); try { string pw = provider2.GetPassword("foo", "wrong"); Assert.Fail("Should have failed"); } catch (MembershipPasswordException) { } }
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); try { string password = provider.GetPassword("foo", answer); if (!enablePasswordRetrieval) Assert.Fail("This should have thrown an exception"); Assert.AreEqual("barbar!", password); } catch (MembershipPasswordException) { if (requireQA && answer != null) Assert.Fail("This should not have thrown an exception"); } catch (ProviderException) { if (requireQA && answer != null) Assert.Fail("This should not have thrown an exception"); } }
public void GetPasswordWithNullValues() { MembershipCreateStatus status; provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("requiresQuestionAndAnswer", "false"); config.Add("enablePasswordRetrieval", "true"); config.Add("passwordFormat", "clear"); config.Add("applicationName", "/"); provider.Initialize(null, config); MembershipUser user = provider.CreateUser("foo", "barbar!", "*****@*****.**", null, null, true, null, out status); Assert.IsNotNull(user); string pw = provider.GetPassword("foo", null); Assert.AreEqual("barbar!", pw); }