private void btnLogin_Click(object sender, EventArgs e) { string password1 = "", passworrd; string username = txtUsername.Text.Trim(); password1 = EncryptData.Encrypt(txtPassword.Text.Trim()); passworrd = EncryptData.ConvertStringToHex(password1, System.Text.Encoding.Unicode); //passworrd = password1.Replace('*', '/'); if (IncorrectLoginCount > 2) { MetroMessageBox.Show(this, "Your Account has been locked! Contact Administrator to Unlock your account and change you password!", "Account Lock!"); } else { if (username == "" || passworrd == "") { MetroMessageBox.Show(this, "Username and Password Cannot be Blank!", "Input Error"); } else { User user = UserController.CheckEmailExist(username, passworrd); if (user.Email == null) { MetroMessageBox.Show(this, "Username or Password Does not exist!", "Incorrect Login!"); } else if (user.RsaID == null && user.Email != null) { MetroMessageBox.Show(this, "Username or Password Does not exist!", "Incorrect Login!"); IncorrectLoginCount++; if (IncorrectLoginCount > 2) { //Lock Account on DB } } else if (user.RsaID != null && user.Email != null) { if (user.AccountStatus == "Locked") { MetroMessageBox.Show(this, "Your Account has been locked! Contact Administrator to Unlock your account and change you password!", "Account Lock!"); } else { Main main = new Main(user); this.Hide(); main.Show(); } } } } }
private void btnRegister_Click(object sender, EventArgs e) { //Field Capture //User Details name = txtName.Text.Trim(); ID = txtID.Text.Trim(); surname = txtSurname.Text.Trim(); cell = txtCellNum.Text.Trim(); buznessname = txtBusinessName.Text.Trim(); //Address Details province = txtProvince.Text.Trim(); suurb = txtSuburb.Text.Trim(); street = txtStreet.Text.Trim(); streetnum = txtStreetNumber.Text.Trim(); country = txtCountry.Text.Trim(); City = txtCity.Text.Trim(); //Account Details Email = txtEmail.Text.Trim(); //password = txtPassword.Text.Trim(); //convirmpassword = txtConfirmPassword.Text.Trim(); string password1 = EncryptData.Encrypt(txtPassword.Text.Trim()); password = EncryptData.ConvertStringToHex(password1, System.Text.Encoding.Unicode); string Confirm = EncryptData.Encrypt(txtConfirmPassword.Text.Trim()); convirmpassword = EncryptData.ConvertStringToHex(Confirm, System.Text.Encoding.Unicode); //Field Validation List <string> ErrorLog = new List <string>(); //Here comes a lot of Validation //User Details //Name Validation if (name == "") { ErrorLog.Add("Name Field is Blank"); txtName.Style = MetroColorStyle.Red; txtName.UseStyleColors = true; } else if (name.All(char.IsDigit)) { ErrorLog.Add("Name Field Cannot Contain Digits"); txtName.Style = MetroColorStyle.Red; txtName.UseStyleColors = true; } else if (!Regex.IsMatch(name.ToString(), "^[A-Za-z ]+$")) { ErrorLog.Add("Name Field cannot contain special characters!"); txtName.Style = MetroColorStyle.Red; txtName.UseStyleColors = true; } //Surname Validation if (surname == "") { ErrorLog.Add("Surname Field is Blank!"); txtSurname.Style = MetroColorStyle.Red; txtSurname.UseStyleColors = true; } else if (surname.All(char.IsDigit)) { ErrorLog.Add("Surname Field cannot contain digits!"); txtSurname.Style = MetroColorStyle.Red; txtSurname.UseStyleColors = true; } else if (!Regex.IsMatch(surname, "^[A-Za-z ]+$")) { ErrorLog.Add("Surname Field cannot contain special characters!"); txtSurname.Style = MetroColorStyle.Red; txtSurname.UseStyleColors = true; } //ID Validation if (ID == "") { ErrorLog.Add("ID Field is Blank"); txtID.Style = MetroColorStyle.Red; txtID.UseStyleColors = true; } else if (ID.Length != 13) { ErrorLog.Add("ID Field must be 13 characters long."); txtID.Style = MetroColorStyle.Red; txtID.UseStyleColors = true; } else if (!float.TryParse(ID, out float IDNum)) { ErrorLog.Add("ID field can only contain numbers!"); txtID.Style = MetroColorStyle.Red; txtID.UseStyleColors = true; } //Cell Number Validation if (cell == "") { ErrorLog.Add("Cell Number Field is Blank"); txtCellNum.Style = MetroColorStyle.Red; txtCellNum.UseStyleColors = true; } else if (!float.TryParse(cell, out float CellNum)) { ErrorLog.Add("Cell Number field can only contain numbers!"); txtCellNum.Style = MetroColorStyle.Red; txtCellNum.UseStyleColors = true; } //Business Name Validation if (buznessname == "") { ErrorLog.Add("Business Name Field is Blank"); txtBusinessName.Style = MetroColorStyle.Red; txtBusinessName.UseStyleColors = true; } //Beginning of Address Validation //Street Number if (streetnum == "") { ErrorLog.Add("Street Number Cannot be Blank!"); txtStreetNumber.Style = MetroColorStyle.Red; txtStreetNumber.UseStyleColors = true; } else if (streetnum.All(char.IsLetter)) { ErrorLog.Add("Street Number Can only contain digits!"); txtStreetNumber.Style = MetroColorStyle.Red; txtStreetNumber.UseStyleColors = true; } else if (!Regex.IsMatch(streetnum, "^[0-9]+$")) { ErrorLog.Add("Street Number Cannot contain special characters!"); txtStreetNumber.Style = MetroColorStyle.Red; txtStreetNumber.UseStyleColors = true; } //Street Name if (street == "") { ErrorLog.Add("Street Name Cannot be Blank!"); txtStreet.Style = MetroColorStyle.Red; txtStreet.UseStyleColors = true; } else if (street.All(char.IsDigit)) { ErrorLog.Add("Street Name cannot contain digits!"); txtStreet.Style = MetroColorStyle.Red; txtStreet.UseStyleColors = true; } else if (!Regex.IsMatch(street, "^[A-Za-z ]+$")) { ErrorLog.Add("Street Name cannot contain special characters!"); txtStreet.Style = MetroColorStyle.Red; txtStreet.UseStyleColors = true; } //Suburb if (suurb == "") { ErrorLog.Add("Suburb Cannot be Blank!"); txtSuburb.Style = MetroColorStyle.Red; txtSuburb.UseStyleColors = true; } else if (suurb.All(char.IsDigit)) { ErrorLog.Add("Suburb cannot contain digits!"); txtSuburb.Style = MetroColorStyle.Red; txtSuburb.UseStyleColors = true; } else if (!Regex.IsMatch(suurb, "^[A-Za-z ]+$")) { ErrorLog.Add("Suburb cannot contain special characters!"); txtSuburb.Style = MetroColorStyle.Red; txtSuburb.UseStyleColors = true; } //City if (City == "") { ErrorLog.Add("City Cannot be Blank!"); txtCity.Style = MetroColorStyle.Red; txtStreet.UseStyleColors = true; } else if (City.All(char.IsDigit)) { ErrorLog.Add("City cannot contain digits!"); txtCity.Style = MetroColorStyle.Red; txtCity.UseStyleColors = true; } else if (!Regex.IsMatch(City, "^[A-Za-z ]+$")) { ErrorLog.Add("City cannot contain special characters!"); txtCity.Style = MetroColorStyle.Red; txtCity.UseStyleColors = true; } //Province if (province == "") { ErrorLog.Add("Province Cannot be Blank!"); txtProvince.Style = MetroColorStyle.Red; txtProvince.UseStyleColors = true; } else if (province.All(char.IsDigit)) { ErrorLog.Add("Province Cannot contain digits!"); txtProvince.Style = MetroColorStyle.Red; txtProvince.UseStyleColors = true; } else if (!Regex.IsMatch(province, "^[A-Za-z ]+$")) { ErrorLog.Add("Province Cannot contain special characters!"); txtProvince.Style = MetroColorStyle.Red; txtProvince.UseStyleColors = true; } //Country if (country == "") { ErrorLog.Add("Country Cannot be Blank!"); txtCountry.Style = MetroColorStyle.Red; txtCountry.UseStyleColors = true; } else if (country.All(char.IsDigit)) { ErrorLog.Add("Country Cannot contain digits!"); txtCountry.Style = MetroColorStyle.Red; txtCountry.UseStyleColors = true; } else if (!Regex.IsMatch(country, "^[A-Za-z ]+$")) { ErrorLog.Add("Country Cannot contain special characters!"); txtCountry.Style = MetroColorStyle.Red; txtCountry.UseStyleColors = true; } //Beginning of Account Validation //Email Validation try { var addr = new MailAddress(Email); } catch { ErrorLog.Add("Email is not valid!"); txtEmail.Style = MetroColorStyle.Red; txtEmail.UseStyleColors = true; } if (password == "" || convirmpassword == "") { ErrorLog.Add("Password or Confirm Password Cannot be Blank!"); txtPassword.Style = MetroColorStyle.Red; txtPassword.UseStyleColors = true; txtConfirmPassword.Style = MetroColorStyle.Red; txtConfirmPassword.UseStyleColors = true; } else if (password != convirmpassword) { ErrorLog.Add("Passwords do not match!"); txtPassword.Style = MetroColorStyle.Red; txtPassword.UseStyleColors = true; txtConfirmPassword.Style = MetroColorStyle.Red; txtConfirmPassword.UseStyleColors = true; } //List All Errors, if none, continue. if (ErrorLog.Count > 0) { string ErrorMessage = "The following issues have to be resolved:\n\n"; foreach (string item in ErrorLog) { ErrorMessage += item.ToString() + "\n"; } MetroMessageBox.Show(this, ErrorMessage, "Input Errors"); //This is to refresh the tab, to display all the incorrect fields in Red tabUserRegister.SelectTab(1); tabUserRegister.SelectTab(0); } else if (UserController.UpdateUser(CreateNewUer())) { MetroMessageBox.Show(this, "Account Successfully Updated!", "Update Successful"); user = CreateNewUer(); ClearPI(); } }
private void btnRegister_Click(object sender, EventArgs e) { string password1 = ""; string convirmpassword1 = ""; bool cool = true; Email = txtEmail.Text.Trim(); password1 = EncryptData.Encrypt(txtPassword.Text.Trim()); convirmpassword1 = EncryptData.Encrypt(txtConfirmPassword.Text.Trim()); password = EncryptData.ConvertStringToHex(password1, System.Text.Encoding.Unicode); convirmpassword = EncryptData.ConvertStringToHex(convirmpassword1, System.Text.Encoding.Unicode); // password = password1.Replace('/', '*'); //convirmpassword = convirmpassword1.Replace('/', '*'); List <string> ErrorLog = new List <string>(); try { var addr = new MailAddress(Email); } catch { ErrorLog.Add("Email is not valid!"); txtEmail.Style = MetroColorStyle.Red; txtEmail.UseStyleColors = true; } if (password == "" || convirmpassword == "") { ErrorLog.Add("Password or Confirm Password Cannot be Blank!"); txtPassword.Style = MetroColorStyle.Red; txtPassword.UseStyleColors = true; txtConfirmPassword.Style = MetroColorStyle.Red; txtConfirmPassword.UseStyleColors = true; } else if (password != convirmpassword) { ErrorLog.Add("Passwords do not match!"); txtPassword.Style = MetroColorStyle.Red; txtPassword.UseStyleColors = true; txtConfirmPassword.Style = MetroColorStyle.Red; txtConfirmPassword.UseStyleColors = true; } if (ErrorLog.Count > 0) { cool = false; string ErrorMessage = "The following issues have to be resolved:\n\n"; foreach (string item in ErrorLog) { ErrorMessage += item.ToString() + "\n"; } MetroMessageBox.Show(this, ErrorMessage, "Input Errors"); //This is to refresh the tab, to display all the incorrect fields in Red tabCRegister.SelectTab(1); tabCRegister.SelectTab(2); } if (cool) { User user = new User(txtName.Text, txtID.Text, txtSurname.Text, txtCellNum.Text, Address, txtEmail.Text, password, "Active", txtBusiness.Text); if (UserController.registerUser(user)) {// dummy user so fields stay shap in rest of forms // take underscore away Main main = new Main(user); this.Hide(); main.Show(); } } }