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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/609553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:06:31  来源:igfitidea点击:

Authentication of Windows Local User account in C# 3.0

c#.netwindowsauthenticationuser-accounts

提问by JaredPar

How to authenticate local windows user account in C# 3.0. Windows OS on which i have to validate the password is Vista and 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. Please suggest, thanks

如何在 C# 3.0 中验证本地 Windows 用户帐户。我必须验证密码的 Windows 操作系统是 Vista 和 Win2K8。注意:用户帐户是本地帐户而不是域帐户。我在 C# 3.5(PrincipalContext 类)中找到了解决方案,但在 3.0 框架中找不到。请推荐,谢谢

回答by JaredPar

If you are looking to validate local users, you can use LogonUser to do this. It can validate both local and remote users. For local users simply pass the machine name in place of the domain.

如果您要验证本地用户,可以使用 LogonUser 来执行此操作。它可以验证本地和远程用户。对于本地用户,只需传递机器名称来代替域。

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 CloseHandleon the resulting token.

这是验证用户身份的最佳方式。完成会话后,您应该对生成的令牌调用CloseHandle