人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

May 21, 2007

How to check windows username and password

Filed under: Code snippets

WindowsIdentity
http://support.microsoft.com/kb/319615/zh-cn

static public bool CheckAccount(string userName, string pwd)
{
string user = userName;
string domin = System.Environment.MachineName;
IntPtr tokenHandle = new IntPtr(0);

if (userName.Contains(”\\”))
{
string[] arr = userName.Split(new char[] { ‘\\’});
user = arr[1];
domin = arr[0];
}

// Call LogonUser to obtain an handle to an access token.
bool returnValue = LogonUser(user, domin, pwd,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
ref tokenHandle);
return returnValue;
}

[DllImport(”advapi32.dll”, SetLastError = true)]
public extern static bool LogonUser(String lpszUsername, String lpszDomain,
String lpszPassword, int dwLogonType,
int dwLogonProvider, ref IntPtr phToken);

const int LOGON32_PROVIDER_DEFAULT = 0;
//This parameter causes LogonUser to create a primary token.
const int LOGON32_LOGON_INTERACTIVE = 2;
const int SecurityImpersonation = 2;

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2007/05/21/how-to-check-windows-username-and-password/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham