简体   繁体   中英

Setting user password using C# does not work, any ideas?

I need to reset a user password. to do so, I use the following code:

DirectoryEntry de = ..
de.AuthenticationType = AuthenticationType.Secure
de.Password = txtPassword.text
de.CommitChanges()

When i run the code - nothing happens. The user password does not change, and no exception is thrown.

if i use the following method:

de.Invoke("SetPassword", .. );

when i run the code, I get a message that says: Please insert smartcard ...

I have admin privilages over the user account. The user does not have UAV set for smart card.

Any ideas ?

The Password property of the DirectoryEntry class isn't what you think it is. You're not changing the user's password, you're changing the password you're using to access further information from the DirectoryEntry object.

From the MSDN documentation :

You can set the Username and Password properties to specify alternate credentials with which to access the information in Active Directory Domain Services. Any other DirectoryEntry objects retrieved from this instance (for example, through Children) are automatically created with the same alternate credentials.

With your second method, if you're being asked to insert a smartcard I doubt that has anything to do with the user you're modifying - it's more likely it's asking for your smartcard. If you're not set up to use smartcards either, then I'm really not sure why it's asking you for one at all.

Take a look at this related question and see if the answers there help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM