Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 04, 2012 09:27 AM by kyberias
Apr 21, 2008 12:28 PM|LINK
Will anyone tell me how to Authenticate Users with the SQL Server database table using C# with Example?
Membership API controls for Login and Registering Users for authentication,
but i need/require to store Username/Password in a DatabaseTable(SQL SERVER table) in Register.aspx and then Match them against the DB table in Login.aspx page.Plz forward the two files.
I'm doing having great difficulty to accomplish that, Plz anyone provide me with the "Complete Example" Easy to understand and simple code
to authenticate against a DB table
Apr 21, 2008 05:43 PM|LINK
check this out
Apr 23, 2008 02:05 AM|LINK
hi there. you may try these codes.(sorry, its in vb)
blnResult = SiteSpecificAuthenticationMethod(Login1.UserName, Login1.Password)
reader = con2.ExecuteReader()
thats the codes i used for my system. hope that it'll help you.
Jun 27, 2008 05:35 PM|LINK
I'm new here. And i would like to say thanks to acit about his post I would translate that in C#.
As i belive there are lots of other people who wants in C# and most of the places provide too complecated codes.
This one is the simplest and to the point. I just converted it into C#. Please see below setp by step.
Create a page with the name of login.aspx
Place login control on it. It's default id will be login1
Create a another with name main_page.aspx (this page will be you home or default page)
Codding for login.aspx.cs file
_Default : System.Web.UI.Page
sender, EventArgs e)
// Check if the user is already loged in or not
!= null) && (Convert.ToBoolean(Session["Check"])
// If User is Authenticated then moved to a main page
sender, AuthenticateEventArgs e)
blnresult = false;
// Pass UserName and Password from login1 control to an authentication function which will check will check the user name and password from sql server.
// Then will retrun a true or false value into blnresult variable
blnresult = Authentication(Login1.UserName, Login1.Password);
// If blnresult has a true value then authenticate user
if (blnresult ==
// This is the actual statement which will authenticate the user
e.Authenticated = true;
// Store your authentication mode in session variable
// If user faild to provide valid user name and password
// Function name Authentication which will get check the user_name and passwrod from sql database then return a value true or false
username, string password)
sqlstring = "Select user_name, password from [user_table] where user_name='"
+ username + "' and password ='" + password +
// create a connection with sqldatabase
con = new System.Data.SqlClient.SqlConnection(
Data Source=datebaseservername;Initial Catalog=datebasename;UserID=databaseusername;Password=databasepassword;Connect Timeout=10;TrustServerCertificate=True "
// create a sql command which will user connection string and your select statement string
System.Data.SqlClient.SqlCommand comm =
// create a sqldatabase reader which will execute the above command to get the values from sqldatabase
// open a connection with sqldatabase
// execute sql command and store a return values in reade
reader = comm.ExecuteReader();
// check if reader hase any value then return true otherwise return false
coding need to be added in web.config this code will redirect a user to login.aspx page if user is not logged in and also restrict anonymous users.
If you need more help you can e-mail me at
email@example.com or visit www.zeeshanfaisal.com
Sep 06, 2008 12:26 PM|LINK
thank you a lot acit for your post, it will help me to advance in my project, but i have a problem is that the type of 'System.Data.SqlClient.SqlDataReadercon1' is not defiened. do you have any idea if i must download a framework or how to solve the problem?
Your help will make me advance more in my project. thanks in advance
Sep 10, 2008 02:31 AM|LINK
basically the 'system.data.sqlclient.sqldatareadercon1' was to define the connection string that the system will connect to.
i want to simplify my code therefore i used the existed connection string which is 'sqldatasource1'.
there's no need for you to download a framework or anything.
you only need to do a few modification to your codes only.
Oct 22, 2008 10:29 PM|LINK
Data Source=ServerName;Initial Catalog=Database;UserID=userid;Password=passwordi;Connect Timeout=10;TrustServerCertificate=True);
When I run the project this the error I get -->
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1026: ) expected
Line 53: // create a connection with sqldatabase
Line 54: System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(
Line 55: Data Source=Confirm;Initial Catalog=IMB;UserID=sa;Password=mmi;Connect Timeout=10;TrustServerCertificate=True);
Line 57: // create a sql command which will user connection string and your select statement string
Line 53: // create a connection with sqldatabase
Here is what my project is - I have a SQL user database that I would like to use to Authenticate Users to login into my wesite, after they login I need to run a few start procedures based upon a user.
Oct 23, 2008 04:58 AM|LINK
First i want to thank you. Because you found a bug/error in my code.
And i apologies for any inconvenience.
It's a small mistake you just need to add double quotes before and after the connection string.
See the following correct code.
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(
" Data Source=Confirm;Initial Catalog=IMB;UserID=sa;Password=mmi;Connect Timeout=10;TrustServerCertificate=True
In the above string you can see quotes in red color before and after the connection string that's all you need to put in ur code and you are good to go.
I also fixed my above code.
feel free to ask if you have any problem.
Oct 24, 2008 08:05 PM|LINK
Your Awsome thanks!!!![:D]
Can I run something by you?? This is kind of new to me I am a Java/PhP guy. So this is what I am trying to accomplish I have a web server running SQL Server 2005 with a database and a user table.
I need to create a login webpage using the user name and password from the database and then run a SQL Start procedure based upon a user in the table.
Sorry I know it’s kind of long but was wondering if you could point me in the right direction????
Oct 24, 2008 09:18 PM|LINK
As i understand you are already able to authenticate user. Now u want to call a stored procedure from sql database for that user.
Read the following article. It explains how to call sql procedure.