.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Kaviya Balasubramanian
satyapriyanayak
SP
abhays
Sasi Prabhu

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Login Page in C# with use SQL Injection

Posted By:Shashi Ray       Posted Date: September 02, 2008    Points: 10    Category: ADO.NET    URL:   

Login Page in C# with use SQL Injection. You shoud avoid SQL injection.
 

This sample code shows login validation But DO NOT use this code to validate user login

con.Open();

SqlCommand cmd=new SqlCommand ("select count(*) from login where user=@u and pass=@p",con);

cmd.Parameters.Add("@u", SqlDbType.Varchar, 10).Value=TextLogin.Text.Trim();

cmd.Parameters.Add("@p", SqlDbType.Varchar,10).Value=TextPwd.Text.Trim();

int count=(int)cmd.ExecuteScalar();

if(count >0)

{

Response.Redirect("Default.aspx");

}

else

{

LabelError.Text="Invalid User Name or Password";

}

 


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend