How we can login in c-sharp

Aug 30 2011 3:19 AM
hello ;

my question is, how we can create login in c-sharp. it means, if i enter username and password and then i press login button. the name and password compare from the table of "login" that are exist in the sql database . if username and password will be match from the username and password of the database table then display on the top of the web page "welcome MR OR MS XYZ". if the username and password are not match then display "invalid". i am writing this code in the login button. can u help me ?


protected void Button_login_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("select * from login where [user_name]='"+TextBox_user_name.Text+"' and [password]='"+TextBox_password.Text+"'");
            cmd.Connection = connection.get();
            cmd.Parameters.AddWithValue(" username ",TextBox_user_name.Text);
            cmd.Parameters.AddWithValue(" password",TextBox_password.Text);
            int c = cmd.ExecuteNonQuery();
            if (c == 0)
            {
                Label_result.Text = "invalid user name and password";


            }
            else
                Label_display_user_name.Text = "WELLCOME ";
     
       
       
        }


regards
sumaira



Answers (5)