This is a followup post to using active directory for user validation. I have been successful in making the validateUser method work, but am having trouble getting the changePassword function to work. It seems that it has worked at least once, (perhaps the the very first time i try it), but usually fails. I have verified that the password did actually change in active directory when it worked. When I try a second time, I get the error "The password supplied is invalid. Passwords must conform to the password strength requirements configured for the default provider.". On my domain controller, I checked the password rules and this shouldn't be happening (or I don't see what it causing it). I have no minimums set.
If I remove the two lines (minPasswordLength and minNonAlpha) from my config.sys, it give me an error that password must be 7 characters. If I enter 7 characters, it gives me an alpha error. If I include a password such as "1@a111111", it still gives me the "Non alpha numeric characters in 'newPassword' needs to be greater than or equal to '1'." error. I can't seem to find the right combination.
Is there a way to make it respect the complexity rules setup for the domain? Can anyone shed light on this? Here is the code, and the web.config
public string ChangePassword(string domain, string username, string oldPassword, string newPassword)
{
try
{
if (domain.Length > 0)
username = username + "@" + domain.ToString();
MembershipProvider mp = Membership.Providers["ADMembershipProvider"];
bool b = mp.ChangePassword(username, oldPassword, newPassword);
return b.ToString();
}
catch (Exception ex)
{
return ex.Message;
}
}
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="CustomerConnectionString" connectionString="LDAP://mydomain.com"/>
</connectionStrings>
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
<authentication mode="Windows"/>
<membership defaultProvider="ADMembershipProvider">
<providers>
<add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="CustomerConnectionString"
connectionUsername=administrator@mydomain.com
connectionPassword="mypasswordt"
minRequiredPasswordLength="1"
minRequiredNonalphanumericCharacters="0"
/>
</providers>
</membership>
</system.web>
</configuration>