I am trying to setpassword with for forget password functionality.
public string SetPassWord(string userName, string randomPassword)
{
string result = string.Empty;
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, userName);
AdUser adUser = new AdUser();
if (user != null)
{
user.SetPassword(randomPassword);
result = "Success";
}
return result;
}
I need to generate the random password which meets the following complexity:
- Not contain the user's account name or parts of the user's full name that exceed two consecutive characters
- Be at least six characters in length
- Contain characters from three of the following four categories:
- English uppercase characters (A through Z)
- English lowercase characters (a through z)
- Base 10 digits (0 through 9)
- Non-alphabetic characters (for example, !, $, #, %)
Complexity requirements are enforced when passwords are changed or created.
Is there any inbuilt method which serves the above requirements? I have used below method to generate password randomely:
string randomPassword = Membership.GeneratePassword(8, 0).Replace('<','!').Replace('>', '#');
It throws the error when I am trying to set password. Appreciate if there is and validation or inbuilt method to achieve the above requirement.
Not contain the user's account name or parts of the user's full name that exceed two consecutive charactersrequires a separate regex or process. The rest can be validated with a single regex. - user557597