Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I'm creating login page and registration form also.I entered some values in regestration forn and saved.now i want to login from those values(user id& password).Please solve my problem.
Posted

see reference

http://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.80).aspx[^]

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx[^]

or
SqlConnection objConnection = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connectionString"].ToString());
               SqlCommand objCommand = new SqlCommand();
               SqlDataReader dr;
               objConnection.Open();
               objCommand.Connection = objConnection;
               objCommand.CommandType = CommandType.Text;
               objCommand.Parameters.Clear();
               objCommand.CommandText = "select Count(*) from Table_Name where [UserId]='" + UserId + "' and [Password]='" + Password + "' and Status='A' ";
               int val = int.Parse(objCommand.ExecuteScalar().ToString());
               if (val > 0)
               {
                   while (dr.Read())
                   {
                       //like this retrieve all values
                       if (dr["UserId"] != System.DBNull.Value)
                       {
                           if (dr.HasRows == true)
                           {
                               int UserId = Convert.ToInt32(dr["UserId"]);
                           }
                       }
                       if (dr["Password"] != System.DBNull.Value)
                       {
                           if (dr.HasRows == true)
                           {
                               string Slno = dr["Password"];
                           }
                       }
                   }
               }
 
Share this answer
 
if u saved the details successfully then what is the problem in retrieving them from database ?
just retrieve the credentials from database then compare the values entered for user Id and password fields in login button click if matched redirect the user to another page (the page which can be viewed after logging in),else display a message credentials not found.

the above process for simple login.
In addition to these for security purpose you can provide authentication and autherization in your application.
 
Share this answer
 

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