Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey guys,

im having trouble in making the login process. I have already made a database and its connected to my web application. my question is how can you login using the data that was entered in the database? Please help. Sorry im just a beginner.
Posted

1 solution

It's very easy to login with your database in application. Here, you can see the login process.
C#
protected void btnLogin_Click(object sender, EventArgs e)
   {
       SqlConnection cnn = new SqlConnection("Add your connection String here.");
       SqlDataAdapter da = new SqlDataAdapter("Select * from tblRegistration where username= '" + txtusername.Text + "' and password = '" + txtpassword.Text + "'",cnn);
       DataSet ds = new DataSet();
       da.Fill(ds);

       if (ds.Tables[0].Rows.Count != 0)
       {
           Session["username"] = ds.Tables[0].Rows[0][0].ToString();
           Response.Redirect("Home.aspx");
       }
   }


I hope this example is helping to you........!!!!!!
 
Share this answer
 
v2
Comments
Member 10302214 28-Sep-13 2:58am    
Thank you very much! This really helped :)
Chintan Desai1988 28-Sep-13 3:00am    
welcome dear.....:-)
Homero Rivera 28-Sep-13 2:58am    
That'll make a hacker's day don't you think?
All straight concatenations makes it a target for SQL Injection
Chintan Desai1988 28-Sep-13 3:01am    
I have all solution to protect from hacker bt here they want only the ans of his query okeys.
Homero Rivera 28-Sep-13 3:06am    
Well, I guess our newbie friend should know that there is more to be learned. I didn't downvote your solution, but someone else has and I think it was because of that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900