Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
first i am creating database and enter the values manually in the database itself.

database fields as follows; (Table name test)

Login id 1
Firs tname ram
Last name kumar
Password 123
Lastlogin time 1.31 PM

Then i am creating the Login page design as follows;

Username textbox1
Password textbox2


in the run mode i type the username 1 and password from the table (test) i am creating manually that loginid and password i am typing to this loginpage(run mode)

when i type username 1 and password 123. and click the insert button i want to show the message valid loginid and password.

suppose i type wrong username and password i want to show the message invalid login and password.

for that i how to write the code in asp.net with c sharp. it is web application project. please help me
Posted

 
Share this answer
 
C#
string SqlConnect = System.Configuration.ConfigurationManager.ConnectionStrings["Connect"].ConnectionString;
        SqlConnection Sqlconn = new SqlConnection(SqlConnect); 
        SqlCommand sqlcomm = new SqlCommand("select email,userpassword from signup where email='" + TextBox1.Text + "' and userpassword='" + TextBox2.Text + "'",Sqlconn);
        Sqlconn.Open();
        SqlDataReader dr = sqlcomm.ExecuteReader();
        if (dr.HasRows)
        {
            Session["email"] = TextBox1.Text;
            dr.Close();
            Sqlconn.Close();
Label1.Text = "Email-ID or Password you entered Is Valid !";
            
        }
        else
        {

            Label1.Text = "Email-ID or Password you entered do not match !";
            Label1.ForeColor = System.Drawing.Color.DarkGreen;

        }
 
Share this answer
 
C#
protected void loginbtn_Click(object sender, EventArgs e)
        {
            string cmd = new "SELECT * FROM Users";
          
            SqlDataAdapter da = new SqlDataAdapter(cmd,con);
            DataTable dt = new DataTable();
            da.Fill(dt);

            string msg = "";         

            foreach(DataRow dr in dt.Rows)
            {
                if(unameTxt.Text == dr["username"].ToString() && pswdTxt.Text == dr["password"].ToString())
                  msg = "Success";
                else
                  msg = "Error";
                 
            }
        }
 
Share this answer
 
 
Share this answer
 
Collapse | Copy Code

protected void login_Click(object sender, EventArgs e)
{
string cmd1 = "SELECT * FROM ACC";

SqlDataAdapter da = new SqlDataAdapter(cmd1,con);
DataTable dt = new DataTable();
da.Fill(dt);



foreach(DataRow dr in dt.Rows)
{
if(unameTxt.Text == dr["username"].ToString() && pswdTxt.Text == dr["password"].ToString())
messagebox.show("login successfuly");
else
messagebox.show("login failed");

}
}
 
Share this answer
 
v2

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