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

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: http://www.dotnetspark.com  

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


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)






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




Further Readings:


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