Use the method of implementing Windows login in ASP.NET.

xiaoxiao2021-03-06  96

Public Bool Login (String Username, 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 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);

转载请注明原文地址:https://www.9cbs.com/read-104172.html

New Post(0)