简体   繁体   English

C#,针对活动目录的身份验证

[英]C# ,Authentication against active directory

I am using PrincipalContext (from the System.DirectoryServices.AccountManagement namespace) for authentication in my application against Active Directory (I am using the ValidateCredentials function). 我正在使用PrincipalContext (来自System.DirectoryServices.AccountManagement命名空间)在我的应用程序中针对Active Directory进行身份验证(我正在使用ValidateCredentials函数)。

The authentication works fine, when I am resetting a user password in Active Directory and forcing him to change password in the next login I can't authenticate the user. 当我在Active Directory中重设用户密码并强迫他在下次登录时更改密码时,身份验证工作正常,我无法对该用户进行身份验证。

I tried to change the way that I am doing authentication, I used LdapConnection (namespace System.DirectoryServices.Protocols ), authentication worked ok, when I reset the user password and force the user to change password in the next login, I can't authenticate this user, if I am only resetting the password and not forcing the user to change password at the next login, I can authenticate the user. 我尝试更改身份验证的方式,我使用了LdapConnection (命名空间System.DirectoryServices.Protocols ),身份验证正常,当我重置用户密码并强制用户在下次登录时更改密码时,我无法对这个用户进行身份验证,如果我仅重置密码而不是强制用户在下次登录时更改密码,则可以对用户进行身份验证。

I tested the same scenario with a different active directory and it worked in all scenarios. 我使用不同的活动目录测试了相同的方案,并且该方案在所有方案中均有效。

Is it possible that Active Directory is preventing me from authenticate through code, when user must change password in the next login flag is true ? 当用户必须在下一个登录标志为true时更改密码时,Active Directory是否有可能阻止我通过代码进行身份验证?

You've answered your own question really, when "User must change password at next logon" is set in active directory, the user can only authenticate interactively from the Windows UI in order to set a new password, they cannot be authenticated in the way you require. 您确实回答了自己的问题,如果在活动目录中设置了“用户必须在下次登录时更改密码”,则用户只能从Windows UI进行交互身份验证以设置新密码,而不能以这种方式进行身份验证您需要。

If you wanted to get it working you would need to add functionality to your application to detected when a user much change their password and provide means to do so prior to authentication. 如果要使其正常运行,则需要在您的应用程序中添加功能,以检测用户何时更改了密码,并提供了在身份验证之前进行更改的方法。 This would require handling of expired passwords as well as instances where changing the password was forced in the way you describe. 这将需要处理过期的密码以及以您描述的方式强制更改密码的实例。

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

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