在ASP.Net 中使用实现windows登陆的方法.

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

public bool Login(string UserName, string Password, string Domain)

{

string text1 = Domain.Trim();

string text2 = UserName.Trim();

text2 = text2.Replace("/", @"\");

int num1 = text2.IndexOf('\\');

if (num1 != -1)

{

text1 = text2.Substring(0, num1);

text2 = text2.Substring(num1 + 1);

}

else

{

num1 = text2.IndexOf('@');

if (num1 != -1)

{

text1 = text2.Substring(num1 + 1);

text2 = text2.Substring(0, num1);

}

}

return this.authenticateUser(text2, Password.Trim(), text1);

}

private bool authenticateUser(string UserName, string Password, string Domain)

{

bool flag1 = false;

try

{

int num1;

IntPtr ptr1;

if (!WindowsAuth.LogonUser(UserName, Domain, Password, 2, 0, out num1))

{

return flag1;

}

ptr1 = new IntPtr(num1);

WindowsIdentity identity1 = new WindowsIdentity(ptr1);

WindowsPrincipal principal1 = new WindowsPrincipal(identity1);

HttpContext.Current.User = principal1;

FormsAuthentication.SetAuthCookie(principal1.Identity.Name, false);

FormsAuthentication.RedirectFromLoginPage(UserName, false);

flag1 = true;

}

catch (Exception)

{

}

return flag1;

}

[DllImport("advapi32.dll")]

public static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out int phToken);

[url=http://www.sangwei.com/][/url]

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航