P
Paul Gallagher
We are having a problem creating an Active Directory USer (DirectoryEntry) programmatically using the .NET framework 1.1
In our development environment we are able to bind to AD using LDAP and create a new directory entry. We comit this and the DirectoryEntry is created using a blank password as shown below:
DirectoryEntry user = users.Add("CN=" + myUsername, "user");
user.Properties["samAccountName"].Add(username); // Login name
user.Properties["givenName"].Add(FirstName); // First Name
user.Properties["sn"].Add(LastName); // Last Name
...other properties...
user.CommitChanges();
We are then able to Invoke SetPassword method to change the password.
Unfortunately this will not work in production since a password policy with a minimum password length is in force. It is not possible to create an Active Directory user with a blank password.
The following error is thrown in this case:
The server is unwilling to process the request.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: The server is unwilling to process the request.
If we try and set the password property as follows:
DirectoryEntry user = users.Add("CN=" + myUsername, "user");
user.Properties["samAccountName"].Add(username); // Login name
user.Properties["givenName"].Add(FirstName); // First Name
user.Properties["sn"].Add(LastName); // Last Name
...other properties...
user.Properties["userPassword"].Add(Mypassword);
user.CommitChanges();
The password is till not set and therefore fails in an environment with a minium length password policy in place.
How we can create a DirectoryEntry where a minimum length password policy exists?
In our development environment we are able to bind to AD using LDAP and create a new directory entry. We comit this and the DirectoryEntry is created using a blank password as shown below:
DirectoryEntry user = users.Add("CN=" + myUsername, "user");
user.Properties["samAccountName"].Add(username); // Login name
user.Properties["givenName"].Add(FirstName); // First Name
user.Properties["sn"].Add(LastName); // Last Name
...other properties...
user.CommitChanges();
We are then able to Invoke SetPassword method to change the password.
Unfortunately this will not work in production since a password policy with a minimum password length is in force. It is not possible to create an Active Directory user with a blank password.
The following error is thrown in this case:
The server is unwilling to process the request.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: The server is unwilling to process the request.
If we try and set the password property as follows:
DirectoryEntry user = users.Add("CN=" + myUsername, "user");
user.Properties["samAccountName"].Add(username); // Login name
user.Properties["givenName"].Add(FirstName); // First Name
user.Properties["sn"].Add(LastName); // Last Name
...other properties...
user.Properties["userPassword"].Add(Mypassword);
user.CommitChanges();
The password is till not set and therefore fails in an environment with a minium length password policy in place.
How we can create a DirectoryEntry where a minimum length password policy exists?