I want to create a Registration and Log In form on Visual Studio 2010 (with Visual C#).
I have created Service-Based Database and one table. I can insert data into the table (at the registration form), but I cannot figure out how to log in the user.
I have a very simple Log In Form (just fields for username and password) and a 'Log In' Button. I do not really know how to check if the password and the username (that exist in my database) match. Here is what I have so far:
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "" & textBox2.Text != "")
{
cn.Open(); // cn is the Sqlconnection
cmd.Parameters.AddWithValue("@Username", textBox1.Text); // cmd is SqlCommand
cmd.Parameters.AddWithValue("@Password", textBox2.Text);
if (cmd.CommandText == "SELECT * FROM Table1 WHERE username = @Username AND password = @Password")
{
MessageBox.Show("Loggen In!");
this.Close();
}
cn.Close();
}
}
cmdis already defined somewhere else in the code? you'll need to execute that command against the db, setting theCommandTextdoes not actually check the database. and we'll ignore the fact that it appears you're storing passwords in plaintext...for now