Thursday, February 24, 2011

Membership minimum password requirements in dotnet

Silly bug encountered in .NET while setting up minimum password requirements for a registration form. Adding the System.Web.Security.SqlMembershipProvider to web.config would set the minimum requirements to be 6 letters and 1 number using the regular expression passwordStrengthRegularExpression = "(?=.{6,})(?=(.*\d){1,})". But when registering the user you would still get an exception stating "{"Non alpha numeric characters in 'newPassword' needs to be greater than or equal to '1'."}



This happens because if you don't specify minRequiredNonalphanumericCharacters="0" .NET assumes minRequiredNonalphanumericCharacters to be 1. The correct config is to specify minRequiredNonalphanumericCharacters = "0"