protected override IEnumerable <CollectedItem> collectDataForSystemItem(ItemType systemItem) { base.ExecutionLogBuilder.CollectingDataFrom(TargetHostName); var collectedLockoutPolicies = PasswordPolicyHelper.getUserModalsInfo3(TargetHostName); this.MapLockoutPoliciesToLockoutItemType((lockoutpolicy_item)systemItem, collectedLockoutPolicies); return(new ItemTypeHelper().CreateCollectedItemsWithOneItem(systemItem, BuildExecutionLog())); }
public void TestValidateAllFailsSpecial() { var pp = new PasswordPolicy { MinimumPasswordLength = 5, MustContainDigits = true, MustContainLowerCaseCharacters = true, MustContainSpecialCharacters = true, MustContainUpperCaseCharacters = true }; Assert.Throws <ValidationException>(() => PasswordPolicyHelper.ValidatePassword(pp, "12345aA")); }
public void TestValidateNullPasswordFails() { var pp = new PasswordPolicy { MinimumPasswordLength = 5, MustContainDigits = false, MustContainLowerCaseCharacters = false, MustContainSpecialCharacters = false, MustContainUpperCaseCharacters = false }; Assert.Throws <ValidationException>(() => PasswordPolicyHelper.ValidatePassword(pp, null)); }
public void TestValidateMustContainUpperCaseCharsPasses() { var pp = new PasswordPolicy { MinimumPasswordLength = 1, MustContainDigits = false, MustContainLowerCaseCharacters = false, MustContainSpecialCharacters = false, MustContainUpperCaseCharacters = true }; Assert.DoesNotThrow(() => PasswordPolicyHelper.ValidatePassword(pp, "aaaaAA")); }
public void TestGetDefaultPasswordPolicy() { PasswordPolicy passwordPolicy = PasswordPolicyHelper.GetDefaultPasswordPolicy(); Assert.IsNotNull(passwordPolicy); }
/// <summary> /// Called before saving the enumeration of entities. /// </summary> /// <param name="entities">The entities.</param> /// <param name="state">The state.</param> /// <returns> /// True to cancel the save operation; false otherwise. /// </returns> public bool OnBeforeSave(IEnumerable <IEntity> entities, IDictionary <string, object> state) { long passwordFieldId = Entity.GetId("core:password"); IList <IEntity> enumerable = entities as IList <IEntity> ?? entities.ToList( ); foreach (IEntity entity in enumerable) { var userAccount = entity.As <UserAccount>( ); if (userAccount == null) { continue; } EntityFieldCache.Instance.Get(0); _auditLogEventTarget.GatherAuditLogEntityDetailsForSave(userAccount, state); var writableCacheKey = new EntityFieldModificationCache.EntityFieldModificationCacheKey((( IEntityInternal )entity.Entity).ModificationToken); IEntityFieldValues cachedFieldValues; if (EntityFieldModificationCache.Instance.TryGetValue(writableCacheKey, out cachedFieldValues)) { object newPassword; if (cachedFieldValues.TryGetValue(passwordFieldId, out newPassword)) { string password = newPassword as string; var userAccountInternal = userAccount as IEntityInternal; var savedUserAccount = Entity.Get <UserAccount>(userAccount.Id); if (!userAccountInternal.IsTemporaryId && password == savedUserAccount.Password) { // Password is unchanged continue; } // Validate the password against the password policy PasswordPolicyHelper.ValidatePassword(PasswordPolicyHelper.GetDefaultPasswordPolicy(), password); // Hash the password before saving userAccount.Password = CryptoHelper.CreateEncodedSaltedHash(password); // The password field was modified, so set the last password change date. userAccount.PasswordLastChanged = DateTime.UtcNow; } } if (HasUserAccountStatusChanged(userAccount)) { if (userAccount.AccountStatus_Enum == UserAccountStatusEnum_Enumeration.Active && userAccount.BadLogonCount > 0) { // Reset the bad logon account when the account is made active again. userAccount.BadLogonCount = 0; } } } return(false); }