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
A:
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
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.
JaredPar
2009-03-04 07:28:56
Thanks for the info. It is working perfectly. But am only conerned about the logon sessions it creates. I dont have much idea on this. Is this a good approach to follow when we need to just validate the pwd? Should i need to write code to logoff the session? Is there any straight way to validate pwd
2009-03-04 10:03:39
It's fine. It's the same API that any service would use to validate a user's credentials. A logon type of NETWORK (3) I believe will not load a user's profile or anything like that. Just be sure to close the handle returned.
Josh Einstein
2009-05-24 19:11:47