コード例 #1
0
        private void Test_UserLocking_Valid(AccountStatus accountStatus)
        {
            IMembershipSettings membershipSettings = Workmate.Components.InstanceContainer.MembershipSettings;

            membershipSettings.MaxInvalidPasswordAttempts = 3;

            IApplicationSettings applicationSettings = Workmate.Components.InstanceContainer.ApplicationSettings;

            WorkmateRoleProvider       roleProvider       = new WorkmateRoleProvider();
            WorkmateMembershipProvider membershipProvider = new WorkmateMembershipProvider();

            string password = "******";

            IUserBasic userBasic = CreateUser(applicationSettings, this.Application, this.DummyDataManager, roleProvider, membershipProvider, password, accountStatus);

            IUserBasic         validatedUser;
            ValidateUserStatus validateUserStatus;

            for (int i = 0; i < membershipSettings.MaxInvalidPasswordAttempts; i++)
            {
                validateUserStatus = membershipProvider.ValidateUser(this.Application.ApplicationId, userBasic.UserName, "465", out validatedUser);
                Assert.AreEqual(ValidateUserStatus.WrongPassword, validateUserStatus);
            }
            // by the next attempt we expect the user to be locked
            validateUserStatus = membershipProvider.ValidateUser(this.Application.ApplicationId, userBasic.UserName, "123", out validatedUser);
            Assert.AreEqual(ValidateUserStatus.UserIsLockedOut, validateUserStatus);

            // test unlock
            Assert.IsTrue(membershipProvider.UnlockUser(userBasic.UserId));
            userBasic = membershipProvider.GetUserBasic(userBasic.UserId, false);
            Assert.AreEqual(accountStatus, userBasic.AccountStatus);
        }
コード例 #2
0
        public void Test_ResetPassword()
        {
            IMembershipSettings  membershipSettings  = Workmate.Components.InstanceContainer.MembershipSettings;
            IApplicationSettings applicationSettings = Workmate.Components.InstanceContainer.ApplicationSettings;

            WorkmateRoleProvider       roleProvider       = new WorkmateRoleProvider();
            WorkmateMembershipProvider membershipProvider = new WorkmateMembershipProvider();

            string password    = "******";
            string newPassword = "******";

            IUserBasic userBasic = CreateUser(applicationSettings, this.Application, this.DummyDataManager, roleProvider, membershipProvider, password, AccountStatus.Valid);

            IUserBasic         validatedUserBasic;
            ValidateUserStatus validateUserStatus = membershipProvider.ValidateUser(this.Application.ApplicationId, userBasic.Email, password, out validatedUserBasic);

            Assert.AreEqual(ValidateUserStatus.Valid, validateUserStatus);

            ChangePasswordStatus changePasswordStatus = membershipProvider.ResetPassword(this.Application.ApplicationId, userBasic, newPassword);

            Assert.AreEqual(ChangePasswordStatus.Success, changePasswordStatus);

            validateUserStatus = membershipProvider.ValidateUser(this.Application.ApplicationId, userBasic.Email, newPassword, out validatedUserBasic);
            Assert.AreEqual(ValidateUserStatus.Valid, validateUserStatus);
        }