public static T AutoSetPassword <T>(this IPasswordPolicy policy, T @object, Expression <Func <T, string> > propertyAccessor) { var password = policy.Generate(); Expression <Action <T, string> > assigner = SetPropertyValue(propertyAccessor); assigner.Compile()(@object, password.SecurePassword); return(@object); }
public static string RenderUniquePassword(this IPasswordPolicy policy, Func <string, bool> result, int maxAttempt = 3) { bool status; string finalPassword; do { RandomSecurePassword securePassword = policy.Generate(); finalPassword = securePassword.SecurePassword; status = result(finalPassword); maxAttempt--; } while (status && maxAttempt > 0); return(status == false ? finalPassword : string.Empty); }
public static T RenderPassword <T>(this IPasswordPolicy policy, T @object, Action <T, RandomSecurePassword> result) { result(@object, policy.Generate()); return(@object); }