/// <summary> /// Saves the registration data of the new user. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSubmit_Click(object sender, EventArgs e) { if (txtUsername.Text == "" || txtPassword.Text == "") { MessageBox.Show("Please fill mandatory fields!(*)"); } else { using (SqlConnection sqlConn = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\Marius\source\repos\ProiectIP\DataBase\LoginDB.mdf; Integrated Security = True; Connect Timeout = 30")) { sqlConn.Open(); SqlCommand sqlCmdID = new SqlCommand("ResetID", sqlConn); sqlCmdID.ExecuteNonQuery(); SqlCommand sqlCmd = new SqlCommand("UserAdd", sqlConn); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text.Trim()); sqlCmd.Parameters.AddWithValue("@LastName", txtLastName.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Age", txtAge.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Username", txtUsername.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Password", Cript.SHA256hash(txtPassword.Text.ToString())); sqlCmd.Parameters.AddWithValue("@Adress", txtAdress.Text.Trim()); sqlCmd.Parameters.AddWithValue("@PhoneNumber", txtPhoneNumber.Text.Trim()); sqlCmd.ExecuteNonQuery(); MessageBox.Show("Registration is succesfull! Now log in to your new account!"); this.Hide(); LoginForm login = new LoginForm(); login.Show(); } } }
/// <summary> /// Checks if username and password are valid and then logs to the shop. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLogin_Click(object sender, EventArgs e) { using (SqlConnection sqlCon = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Marius\source\repos\ProiectIP\DataBase\LoginDB.mdf;Integrated Security=True;Connect Timeout=30")) { string query = "Select * from [Table] where Username = '******' COLLATE SQL_Latin1_General_CP1_CS_AS and Password= '******' COLLATE SQL_Latin1_General_CP1_CS_AS"; SqlDataAdapter sdata = new SqlDataAdapter(query, sqlCon); DataTable dtbl = new DataTable(); sdata.Fill(dtbl); if (dtbl.Rows.Count == 1) { MainForm objMain = new MainForm(); this.Hide(); objMain.Show(); DisplayEmail(); DisplayName(); DisplayAdress(); } else { MessageBox.Show("Invalid username and/or password!"); } } }