コード例 #1
0
        public void PasswordAttemptSucceededTest()
        {
            User user = ClientMembershipService.GetUser("timm");
            string passwordSalt = "1U3h6r/tQ+dGWhLm9Unyng==";
            PasswordFormat passwordFormat = PasswordFormat.Hashed;
            int failedPasswordAttemptCount = 0;
            DateTime failedPasswordAttemptWindowStart = DateTime.MinValue;
            int failedPasswordAnswerAttemptCount = 0;
            DateTime failedPasswordAnswerAttemptWindowStart = DateTime.MinValue;

            ClientMembershipUser target = new ClientMembershipUser(user,
                passwordSalt, passwordFormat, failedPasswordAttemptCount,
                failedPasswordAttemptWindowStart, failedPasswordAnswerAttemptCount,
                failedPasswordAnswerAttemptWindowStart);

            target.PasswordAttemptSucceeded();

            Assert.AreEqual(DateTime.MinValue, target.FailedPasswordAttemptWindowStart);
            Assert.AreEqual(0, target.FailedPasswordAttemptCount);
            Assert.AreEqual(false, target.IsLockedOut);
            Assert.AreEqual(DateTime.MinValue, target.LastLockoutDate);
        }
コード例 #2
0
        private void ValidateUserWithPassword(ClientMembershipUser user,
            string password, bool throwIfFails)
        {
            if (password != null)
            {
                password = password.Trim();
            }

            SecurityHelper.CheckParameter(password,
                true, true, true, 
                this.Application.MaxPasswordAnswerSize,
                "password");

            string passwordFromPersistence =
                this.GetPasswordFromPersistence(user);

            try
            {
                if (!this.CheckPassword(password,
                    passwordFromPersistence,
                    user.PasswordFormat, user.PasswordSalt))
                {
                    user.PasswordAttemptFailed();
                    if (throwIfFails)
                    {
                        throw new SecurityException
                            ("The password supplied was not correct");
                    }
                }
                else
                {
                    user.PasswordAttemptSucceeded();
                }
            }
            finally
            {
                this.PersistUser(user);
            }
        }