private void bottleRadioButton_CheckedChanged(object sender, EventArgs e) { string randId = "BO" + Security.getToken(); Supplier sup = sda.getOneSupplierByID(randId, conn); Supplier deletedSup = sda.getOneDeletedSupplierByID(randId, conn); while ((!string.IsNullOrWhiteSpace(sup.getSupplierID()) && sup.getSupplierID().Equals(randId)) || (!string.IsNullOrWhiteSpace(deletedSup.getSupplierID()) && deletedSup.getSupplierID().Equals(randId))) { randId = "BO" + Security.getToken(); } idTextBox.Text = randId; }
private void sendTokenButton_Click(object sender, EventArgs e) { sup = sda.getOneSupplierByID(idTextbox.Text, conn); if (string.IsNullOrWhiteSpace(idTextbox.Text) || string.IsNullOrEmpty(sup.getSupplierID())) { idErrorLabel.Visible = true; sup = null; } else { token = Security.getToken(); string recipients = sup.getEmail(); string givenName = sup.getSupplierName(); string subject = rs.GetString("resetPasswdEmailSubjectText"); string body = givenName + rs.GetString("resetPasswdEmailBodyText1") + token + rs.GetString("resetPasswdEmailBodyText2"); try { Email.send(recipients, subject, body); MessageBox.Show(rs.GetString("tokenIsSentMsg")); idTextbox.Enabled = false; } catch (System.Net.Mail.SmtpException) { MessageBox.Show(rs.GetString("failToSendMailMsg"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } second = 300; tokenTimer.Start(); } }
private void changePasswordButton_Click(object sender, EventArgs e) { bool error = false; SupplierDA sda = new SupplierDA(); Supplier sup = sda.getOneSupplierByID(supplierID, conn); if (string.IsNullOrWhiteSpace(currentPasswordTextBox.Text) || !Security.verifyHash(currentPasswordTextBox.Text, "SHA512", sup.getPassword())) { currentPasswordErrorLabel.Visible = true; error = true; } else { currentPasswordErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(newPasswordTextBox.Text) || !FormatChecker.checkPasswdFormat(newPasswordTextBox.Text)) { newPasswordErrorLabel.Visible = true; error = true; } else { newPasswordErrorLabel.Visible = false; } if (string.IsNullOrWhiteSpace(confirmPasswordTextBox.Text) || !newPasswordTextBox.Text.Equals(confirmPasswordTextBox.Text)) { confirmPasswordErrorLabel.Visible = true; error = true; } else { confirmPasswordErrorLabel.Visible = false; } if (!error) { sup.setPassword(Security.getHash(newPasswordTextBox.Text, "SHA512", null)); int i = sda.update(sup, sup.getSupplierID(), conn); if (i > 0) { MessageBox.Show(rs.GetString("passwordChangedMsg")); sup = null; } else { MessageBox.Show(rs.GetString("failToChangePasswdMsg"), rs.GetString("errorText"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } currentPasswordTextBox.Clear(); newPasswordTextBox.Clear(); confirmPasswordTextBox.Clear(); }
private void showProfile() { SupplierDA sda = new SupplierDA(); Supplier s = sda.getOneSupplierByID(supplierID, conn); showSupplierIdLabel.Text = s.getSupplierID(); showNameLabel.Text = s.getSupplierName(); showContectNoLabel.Text = s.getContectNo(); showEmailLabel.Text = s.getEmail(); if (s.getProductCategory().Equals("Bottle")) { showCategoryLabel.Text = rs.GetString("bottleText"); } else if (s.getProductCategory().Equals("Package")) { showCategoryLabel.Text = rs.GetString("packageText"); } else if (s.getProductCategory().Equals("Perfume")) { showCategoryLabel.Text = rs.GetString("perfumeText"); } showAddressLabel.Text = s.getAddress(); }
private void loginButton_Click(object sender, EventArgs e) { try { SupplierDA sda = new SupplierDA(); Supplier sup = sda.getOneSupplierByID(idTextbox.Text, conn); SupplierLoginLogDA slda = new SupplierLoginLogDA(); if (!string.IsNullOrWhiteSpace(idTextbox.Text) && !string.IsNullOrEmpty(passwordTextbox.Text)) { if (!string.IsNullOrWhiteSpace(sup.getSupplierID()) && !string.IsNullOrWhiteSpace(sup.getPassword())) { List <LoginLog> logs = slda.searchLogs(DateTime.Now.AddHours(-0.5), DateTime.Now, sup.getSupplierID(), "", conn); bool isLocked = false; DateTime?unlockedTime = null; for (int i = 0; i < logs.Count; i++) { if (logs.ElementAt(i).getLocked()) { isLocked = true; } if (!string.IsNullOrEmpty(logs.ElementAt(i).getUnlockedByEmpID())) { isLocked = false; unlockedTime = logs.ElementAt(i).getTime(); } } if (isLocked) { LoginLog ll = new LoginLog(); ll.setAccountID(sup.getSupplierID()); ll.setSuccess(false); ll.setPasswordIncorrect(false); ll.setLocked(false); ll.setAcStatusTempLock(true); ll.setTime(DateTime.Now); slda.insert(ll, conn); MessageBox.Show(rs.GetString("accountLockedMsg"), "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (unlockedTime.HasValue) { logs = null; logs = slda.searchLogs(unlockedTime.Value.AddMinutes(1), DateTime.Now, sup.getSupplierID(), "", conn); } if (sup.getSupplierID().Equals(idTextbox.Text) && Security.verifyHash(passwordTextbox.Text, "SHA512", sup.getPassword())) { LoginLog ll = new LoginLog(); ll.setAccountID(sup.getSupplierID()); ll.setSuccess(true); ll.setPasswordIncorrect(false); ll.setLocked(false); ll.setAcStatusTempLock(false); ll.setTime(DateTime.Now); slda.insert(ll, conn); for (int i = 0; i < formList.Length; i++) { if (sup.getProductCategory().Equals(formList[i][0])) { Visible = false; mainForm = (Form)Activator.CreateInstance(Type.GetType(GetType().Namespace + "." + formList[i][1] + ".MainForm"), sup.getSupplierID()); mainForm.FormClosed += new FormClosedEventHandler(mainForm_Closed); showStockAlert(sup.getSupplierID(), sup.getProductCategory()); showRecycleBinAlert(sup.getSupplierID(), sup.getProductCategory()); mainForm.ShowDialog(); break; } } } else { int attempts = 1; for (int i = 0; i <= logs.Count; i++) { if (i < logs.Count) { if (logs.ElementAt(i).getPasswordIncorrect()) { if (attempts == 4) { LoginLog ll = new LoginLog(); ll.setAccountID(sup.getSupplierID()); ll.setSuccess(false); ll.setPasswordIncorrect(true); ll.setLocked(true); ll.setAcStatusTempLock(false); ll.setTime(DateTime.Now); slda.insert(ll, conn); MessageBox.Show(rs.GetString("accountLock30MinMsg"), "", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } attempts++; } else if (logs.ElementAt(i).getSuccess()) { attempts = 1; } } else if (i == logs.Count) { LoginLog ll = new LoginLog(); ll.setAccountID(sup.getSupplierID()); ll.setSuccess(false); ll.setPasswordIncorrect(true); ll.setLocked(false); ll.setAcStatusTempLock(false); ll.setTime(DateTime.Now); slda.insert(ll, conn); MessageBox.Show(rs.GetString("idPasswdIncorrectMsg"), "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } } else { MessageBox.Show(rs.GetString("idPasswdIncorrectMsg"), "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show(rs.GetString("inputIdPasswordMsg"), "", MessageBoxButtons.OK, MessageBoxIcon.Information); } idTextbox.Text = ""; passwordTextbox.Text = ""; } catch (MySqlException ex) { Database.showErrorMessage(ex.Number); } catch (Exception) { MessageBox.Show("System error.\nPlease contact administrator.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.ExitThread(); } }