Asp.net logion user login verification code

Source: Internet
Author: User

Web. config

<Configuration>

......

<System. Web>

<Database>

<Add key = "strconn" value = "Server = 107.120.65.99; database = dB; uid = dB; Pwd = DB"/>

</Database>

</System. Web>

......

</Configuration>

 

Global. asax. CS

Protected void session_end (Object sender, eventargs E)

{

Application. Lock ();

Application. Remove (session. sessionid. tostring ());

Application ["ol_usercount"] = (INT) application ["ol_usercount"]-1;

Application. Unlock ();

}

 

Login. aspx

 

<Table class = "logintable">

<Tr> <TD colspan = "2" class = "tdcaption"> <font class = "fcaption"> zookeeper without authorization </font> </TD> </tr>

<Tr> <TD> <font class = "font100"> zookeeper upload ID: </font> </TD> </tr>

<TD> <asp: textbox cssclass = "itxt" id = "txtname" runat = "server"> </ASP: textbox> </TD> </tr>

<Tr> <TD> <font class = "font100"> zookeeper without authorization: </font> </TD>

<TD> <asp: textbox cssclass = "itxt" id = "txtpwd" textmode = "password" runat = "server"> </ASP: textbox> </TD> </tr>

<Tr> <TD> <asp: button cssclass = "iButton" id = "btnsubmit" text = "login" runat = "server"> </ASP: button> </TD>

<TD> <input type = "reset" class = "iButton" name = "btnreset" value = "reset"> </TD> </tr>

</Table>

 

Login. aspx. CS

Using system. Collections. Specialized;

Using system. Data. sqlclient;

 

Public void loginbysql ()

{

String strconn = (string) (namevaluecollection) Context. getconfig ("system. Web/Database") ["strconn"];

Using (sqlconnection conn = new sqlconnection (strconn ))

{

Sqlcommand cmd = new sqlcommand ("sp_idpwd", Conn );

Cmd. commandtype = commandtype. storedprocedure; // The stored procedure is used here.

Cmd. Parameters. Add ("@ ID", sqldbtype. varchar, 20 );

Cmd. Parameters. Add ("@ PWD", sqldbtype. varchar, 20 );

Cmd. Parameters ["@ ID"]. value = txtname. text;

Cmd. Parameters ["@ PWD"]. value = txtpwd. text;

Conn. open ();

 

Using (sqldatareader DR = cmd. executereader ())

{

If (dr. Read ())

{

Bool notol = true;

For (INT I = 0; I <application. Count; I ++)

{

If (application [application. getkey (I). tostring ()]. tostring () = Dr ["userid"]. tostring ())

Notol = false;

}

If (notol)

{

Application [session. sessionid. tostring ()] = Dr ["userid"]. tostring ();

Application ["ol_usercount"] = (INT) application ["ol_usercount"] + 1;

Session ["username"] = Dr ["username"]. tostring (); // sessions
Response. Redirect ("./main/Main. aspx ");

}

Else

Message. Text = "logged in ";

}

Else

{

Message. Text = "Incorrect password ";

}

}

}

}

Stored Procedure
Alter procedure DBO. sp_idpwd
(
@ ID varchar (20 ),
@ PWD varchar (20)
/* @ PWD datatype output */
)
As
Set nocount on
Select * from [dB]. [dB]. [admin] Where (Userid = @ ID) And ([Password] = @ PWD)
Return

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.