login validation from a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bubbles
    New Member
    • Jul 2008
    • 8

    login validation from a table

    i am just a beginner in ASP.NET
    i want to create a login screen in which i can validate the user name and password from a table that i created in an SQL database.
    what process am i supposed to follow after creating the login screen?
    what is the code i might require?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Do you know how to connect to a database using ADO.NET? Google for a tutorial and read it.

    Comment

    • Bubbles
      New Member
      • Jul 2008
      • 8

      #3
      Originally posted by r035198x
      Do you know how to connect to a database using ADO.NET? Google for a tutorial and read it.
      i do know the connection procedure, but what next??

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by Bubbles
        i do know the connection procedure, but what next??
        If you have the user name and password entered on the form, then you can run a select in the users table where user name = EnteredName and password=Entere dPassword. If the query doesn't return any values then the credentials are incorrect.

        Comment

        • Bubbles
          New Member
          • Jul 2008
          • 8

          #5
          Originally posted by r035198x
          If you have the user name and password entered on the form, then you can run a select in the users table where user name = EnteredName and password=Entere dPassword. If the query doesn't return any values then the credentials are incorrect.

          But that's where i am stuck!! what would be the code for traversing my data set to validate if the values that have been entered exist in my table or not.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by Bubbles
            But that's where i am stuck!! what would be the code for traversing my data set to validate if the values that have been entered exist in my table or not.
            You don't need to traverse the dataset. You just need to check if the query returned something, just one value returned means the user exists.
            Post the code you've tried.

            Comment

            • Bubbles
              New Member
              • Jul 2008
              • 8

              #7
              Originally posted by r035198x
              You don't need to traverse the dataset. You just need to check if the query returned something, just one value returned means the user exists.
              Post the code you've tried.
              I have tried the following code:

              Code:
              public SqlConnection connection;
              public SqlDataAdapter dataadapter;
              public DataSet dataset;
              connection = new SqlConnection("database=mydata;server=localhost;");
              connection.Open();
              dataadapter = new SqlDataAdapter("select * from customers", connection);
              dataset = new DataSet();
              dataadapter.Fill(dataset, "table1");
              dataGrid1.DataSource = dataset;
              dataGrid1.DataMember = "table1";
              connection = new SqlConnection();
              connection.ConnectionString = "database=mydata;server=localhost";
              connection.Open();
              dataadapter = new SqlDataAdapter("select * from customers", connection);
              dataset = new DataSet();
              dataadapter.Fill(dataset, "table1");
              dataGrid1.DataSource = dataset;
              dataGrid1.DataMember = "table1";
              is it ok?
              How must i procede from here??

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Your select should select where user name = EnteredUserName and password=Entere dPassword.
                Then you just need to use a DataReader and check its HasRows property.

                Comment

                • Bubbles
                  New Member
                  • Jul 2008
                  • 8

                  #9
                  Originally posted by r035198x
                  Your select should select where user name = EnteredUserName and password=Entere dPassword.
                  Then you just need to use a DataReader and check its HasRows property.
                  Is DataReader the only way out or are there any alternate options?
                  because i have no idea how to work it....pls guide me out of this!

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by Bubbles
                    Is DataReader the only way out or are there any alternate options?
                    because i have no idea how to work it....pls guide me out of this!
                    It's the fastest way
                    Code:
                    using System;
                    using System.Data;
                    using System.Data.SqlClient;
                    .............
                    SqlDataReader dr = null;
                    SqlConnection conn = new SqlConnection(...
                    SqlCommand cmd  = new SqlCommand(
                    			   "select * from Customers where userID"+userID +" and password = "+password, conn);
                    	   try
                    			{
                    			conn.Open();
                    			dr = cmd.ExecuteReader();
                    			if(dr.Read()) {
                    				//customer exists in the database
                    			}
                    			else {
                    				//not there
                    			}
                       ...

                    Comment

                    • Bubbles
                      New Member
                      • Jul 2008
                      • 8

                      #11
                      Originally posted by r035198x
                      It's the fastest way
                      Code:
                      using System;
                      using System.Data;
                      using System.Data.SqlClient;
                      .............
                      SqlDataReader dr = null;
                      SqlConnection conn = new SqlConnection(...
                      SqlCommand cmd  = new SqlCommand(
                      			   "select * from Customers where userID"+userID +" and password = "+password, conn);
                      	   try
                      			{
                      			conn.Open();
                      			dr = cmd.ExecuteReader();
                      			if(dr.Read()) {
                      				//customer exists in the database
                      			}
                      			else {
                      				//not there
                      			}
                         ...
                      i'm yet to try the code but thanx a bunch...you are <Removed!!>!!
                      Last edited by r035198x; Jul 22 '08, 01:05 PM. Reason: No I am not!!!

                      Comment

                      Working...