asp.net logion User Login authentication Code

Source: Internet
Author: User
asp.net

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" >ログイン</font></td></ Tr>


<tr> <td><font class= "font100" >ユーザーID:</font></td></tr>


<td><asp:textbox cssclass= "iTXt" id= "txtname" runat= "Server" ></asp:textbox></td></tr >


<tr> <td><font class= "font100" >パスワード:</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:butto N></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; Stored procedures are 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= "has landed";


}


Else


... {


Message. text= "Password Error";


}


}


}


}


Stored Procedures
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.