简体   繁体   English

使用C#设置用户密码不起作用,有什么想法吗?

[英]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. 用户没有为智能卡设置UAV。

Any ideas ? 有任何想法吗 ?

The Password property of the DirectoryEntry class isn't what you think it is. DirectoryEntry类的Password属性不是您认为的那样。 You're not changing the user's password, you're changing the password you're using to access further information from the DirectoryEntry object. 您没有更改用户的密码,您正在更改用于从DirectoryEntry对象访问更多信息的密码。

From the MSDN documentation : MSDN文档

You can set the Username and Password properties to specify alternate credentials with which to access the information in Active Directory Domain Services. 您可以设置“用户名”和“密码”属性,以指定用于访问Active Directory域服务中的信息的备用凭据。 Any other DirectoryEntry objects retrieved from this instance (for example, through Children) are automatically created with the same alternate credentials. 从此实例检索的任何其他DirectoryEntry对象(例如,通过子项)将使用相同的备用凭据自动创建。

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. 看看这个相关的问题 ,看看那里的答案是否有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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