简体   繁体   English

C#3.0中Windows本地用户帐户的身份验证

[英]Authentication of Windows Local User account in C# 3.0

How to authenticate local windows user account in C# 3.0. 如何在C#3.0中验证本地Windows用户帐户。 Windows OS on which i have to validate the password is Vista and Win2K8. 我必须验证密码的Windows OS是Vista和Win2K8。 Note: User account is a local account and not an domain account. 注意:用户帐户是本地帐户,而不是域帐户。 I found a solution in C# 3.5(PrincipalContext class), but could not find in 3.0 framework. 我在C#3.5(PrincipalContext类)中找到了解决方案,但在3.0框架中找不到。 Please suggest, thanks 请提出建议,谢谢

If you are looking to validate local users, you can use LogonUser to do this. 如果要验证本地用户,则可以使用LogonUser来执行此操作。 It can validate both local and remote users. 它可以验证本地和远程用户。 For local users simply pass the machine name in place of the domain. 对于本地用户,只需将计算机名称代替域即可。

The following blog entry goes into detail about how to call this function from C#. 以下博客条目详细介绍了如何从C#调用此函数。

[ http://alt.pluralsight.com/wiki/default.aspx/Keith.GuideBook/HowToGetATokenForAUser.html] [ http://alt.pluralsight.com/wiki/default.aspx/Keith.GuideBook/HowToGetATokenForAUser.html]

https://web.archive.org/web/20110224015020/http://alt.pluralsight.com/wiki/default.aspx/Keith.GuideBook/HowToGetATokenForAUser.html https://web.archive.org/web/20110224015020/http://alt.pluralsight.com/wiki/default.aspx/Keith.GuideBook/HowToGetATokenForAUser.html

EDIT 编辑

This is the best way to authenticate a user. 这是验证用户身份的最佳方法。 Once you're done with the session, you should call CloseHandle on the resulting token. 完成会话后,应在生成的令牌上调用CloseHandle

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

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