I have been searching for the better part of the morning looking to figure out a way to get a simple login form for a program I am writing for work.
The things that I need for this:
1: User login form 2: Authenticate Usernames and passwords inputed on the form 3: Secure the password string so that it can not be read as plain text. 4: Make it so that Admin users can add other users into the Database.
I can't even get the login form to work correctly let alone the rest of the stuff. Everything that I look at online keeps throwing an error when I click the login button
Error code: SqlException Occured Exception thrown "System.Data.SqlClient.SqlException' in System.Data.dll
Additional Information: Invalid object name 'Login'
I have found where this is at and I do not understand what it is doing or referencing, here is the code for the btnLogin_Click
private void btnLogin_Click(object sender, EventArgs e)
{
{
string USERNAME, PASSWORD;
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\turner.m\Documents\Data.mdf;Integrated Security=True;Connect Timeout=30";
con.Open();
USERNAME = txtUserName.Text;
PASSWORD = txtPassword.Text;
SqlCommand cmd = new SqlCommand("select USERNAME,PASSWORD from Login where USERNAME='" + txtUserName.Text + "'and PASSWORD='" + txtPassword.Text + "'", con);
//cmd.ExecuteNonQuery();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (txtUserName.Text == dr[0].ToString() && txtPassword.Text == dr[1].ToString())
{
txtUserName.Text = "";
txtPassword.Text = "";
this.Hide();
}
else
{
MessageBox.Show("invalid userid or password");
}
dr.Close();
con.Close();
}
}
}