public void TestUnlockUser() { var config = new NameValueCollection(_config); config["enablePasswordRetrieval"] = "true"; config["requiresQuestionAndAnswer"] = "true"; config["maxInvalidPasswordAttempts"] = "1"; config["passwordFormat"] = "clear"; var provider = new MongoMembershipProvider(); provider.Initialize(DefaultName, config); MembershipCreateStatus status; provider.CreateUser("test", "123456", "*****@*****.**", "Question", "Answer", true, null, out status); try { provider.GetPassword("test", "Wrong!"); } catch (MembershipPasswordException) { } // User will now be locked. var lockedOutUser = provider.GetUser("test", false); Assert.IsTrue(lockedOutUser.IsLockedOut); var unlocked = provider.UnlockUser("test"); Assert.IsTrue(unlocked); // User will now be unlocked. var user = provider.GetUser("test", false); Assert.IsFalse(user.IsLockedOut); }
private void TestGetPasswordWithTooManyWrongAnswersWithPasswordFormat(string passwordFormat) { var config = new NameValueCollection(_config); config["enablePasswordRetrieval"] = "true"; config["requiresQuestionAndAnswer"] = "true"; config["maxInvalidPasswordAttempts"] = "2"; config["passwordFormat"] = passwordFormat; var provider = new MongoMembershipProvider(); provider.Initialize(DefaultName, config); MembershipCreateStatus status; provider.CreateUser("test", "123456", "*****@*****.**", "Question", "Answer", true, null, out status); // This is used later to make sure the last lockout date was updated. var dateTimeAtStart = DateTime.Now; try { provider.GetPassword("test", "Wrong!"); } catch (MembershipPasswordException) { } try { provider.GetPassword("test", "Wrong!"); } catch (MembershipPasswordException) { } var user = provider.GetUser("test", false); Assert.IsTrue(user.IsLockedOut); Assert.GreaterOrEqual(user.LastLockoutDate, dateTimeAtStart); }
private void TestGetPasswordWithWrongAnswerWithPasswordRetrievalWithRequiresQAndAWithPasswordFormat(string passwordFormat) { var config = new NameValueCollection(_config); config["enablePasswordRetrieval"] = "true"; config["requiresQuestionAndAnswer"] = "true"; config["passwordFormat"] = passwordFormat; var provider = new MongoMembershipProvider(); provider.Initialize(DefaultName, config); MembershipCreateStatus status; provider.CreateUser("test", "123456", "*****@*****.**", "Question", "Answer", true, null, out status); Assert.Throws<MembershipPasswordException>(() => provider.GetPassword("test", "Wrong!")); }
private void TestGetPasswordWithTooFewWrongAnswersWithPasswordFormat(string passwordFormat) { var config = new NameValueCollection(_config); config["enablePasswordRetrieval"] = "true"; config["requiresQuestionAndAnswer"] = "true"; config["maxInvalidPasswordAttempts"] = "2"; config["passwordFormat"] = passwordFormat; var provider = new MongoMembershipProvider(); provider.Initialize(DefaultName, config); MembershipCreateStatus status; provider.CreateUser("test", "123456", "*****@*****.**", "Question", "Answer", true, null, out status); try { provider.GetPassword("test", "Wrong!"); } catch (MembershipPasswordException) { } var user = provider.GetUser("test", false); Assert.IsFalse(user.IsLockedOut); }