Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Visual-Studio , +
I have created a web form with the login control. Now I want to validate the UserName & the Password with the data on a table in a SQL database (username & password as the fields of the table). I am new to ASP.Net & I need your help thanks.
 
I am using VS 2010 .net Framework 4.0 in win 7 professional 64 bit! SQl server 2008 R2 Developer
Posted 5-May-13 7:35am
Comments
ThePhantomUpvoter at 5-May-13 14:24pm
   
Okay so connect to your database, write a query and execute it.
Chiranthaka Sampath at 5-May-13 20:45pm
   
Ok then what method of that login control to use?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can have a look at How to implement forms authentication and Managing users with roles. There are functionalities available in Asp.NET for user authentication.
 
Possible method using database:
 
SqlConnection conn = new SqlConnection();
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["leave"].ConnectionString;
conn.Open();
string uname = TextBox1.Text;
string ps = Textbox2.Text;
SqlCommand cmd = new SqlCommand("Select uname, pswd from emp_details where uname =@uname and pswd =@ps", conn);
cmd.Parameters.Add(new SqlParameter("@uname", "id here"));
cmd.Parameters.Add(new SqlParameter("@ps", "password here"));
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
       /*Perform operations for authenticated users*/
}
-Additional note:
 
Its advisable to store password in encrypted format in database(Not as plain text). You can make use of algorithm. For example, have a look at Simple String Encryption and Decryption
  Permalink  
v5
Comments
Chiranthaka Sampath at 6-May-13 3:21am
   
Ok I have visited that and then I want to validate that login control's username and the password from a table that in a SQL database. Then how am I going to do that? Please help me!
Rohan Leuva at 6-May-13 3:29am
   
Refer to updated answer. You can accept that answer if it helps you.
Chiranthaka Sampath at 6-May-13 4:01am
   
In here you have develop the code using some sort of new textboxes and buttons but in my case I want to use the Login control of the tools of the VS 2010 and I need the help to add the database to this Login control. Remember that this as ASP.Net form ASP.Net uses the Login control!
Rohan Leuva at 6-May-13 4:43am
   
Refer to this link Asp.net Login Controls

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 6 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100