问题
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
回答1:
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.
The following blog entry goes into detail about how to call this function from C#.
[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.
来源:https://stackoverflow.com/questions/609553/authentication-of-windows-local-user-account-in-c-sharp-3-0