Curtis White Curtis White - 1 year ago 192
ASP.NET (C#) Question

Membership Generate Password alphanumeric only password?

How can I use Membership.GeneratePassword to return a password that ONLY contains alpha or numeric characters? The default method will only guarantee a minimum and not a maximum number of non alphanumeric passwords.

Answer Source
string newPassword = Membership.GeneratePassword(15, 0);
newPassword = Regex.Replace(newPassword, @"[^a-zA-Z0-9]", m => "9" );

This regular expression will replace all non alphanumeric characters with the numeric character 9.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download