private void btnSaveChanges_Click(object sender, EventArgs e) { //initializing variables textOldPassword = ""; textNewPassword = ""; textConfirmPassword = ""; //assigning values to variables textOldPassword = txtOldPassword.Text; textNewPassword = txtNewPassword.Text; textConfirmPassword = txtConfirmPassword.Text; validateForm();//calling form validation if (!isFormValidationOk) { return; } //if form is not validated then exit this function String conPass = encrypter.MD5Hash(txtConfirmPassword.Text); //converting password to md5 hash try { //update query for password String query = "UPDATE `userdetails` SET `password` = '" + conPass + "' WHERE `userdetails`.`userid` = '" + userId + "';"; dbConn.executeQuery(query);//executing query MessageBox.Show("You have sucessfully changed your password."); //clearing text in text fields after sucessful data save. txtOldPassword.Clear(); txtNewPassword.Clear(); txtConfirmPassword.Clear(); this.Close(); } catch (Exception ex) { MessageBox.Show("" + ex.StackTrace); } }
private void btnSignIn_Click(object sender, EventArgs e) { //initializing variables textUsername = ""; textPassword = ""; Encrypter encrypter = new Encrypter(); textUsername = txtUsername.Text; //if password field is not empty then only encrypt it. Else leave it empty if (!string.IsNullOrEmpty(txtPassword.Text)) { textPassword = encrypter.MD5Hash(txtPassword.Text); } //checking if any field is empty validateIfAnyFieldIsEmpty(); if (!isFormValidationOk) { return; } //if form is not validated, dont execute futher lines of code //getting username and password from database if (!getDataFromDatabase()) { return; } //Check if password is correct if (password.Equals(textPassword)) { if (status.Equals("active")) { openUserDashboard(); } else { MessageBox.Show("Your Account is INACTIVE, so please contact Administrator."); } } //show invalid password error else { MessageBox.Show("Your Password doesn't match."); } }
private void btnSignUp_Click(object sender, EventArgs e) { //initializing variables textUsername = ""; textPassword = ""; textConfirmPassoword = ""; comboType = ""; textUsername = txtUsername.Text; textPassword = txtPassword.Text; textConfirmPassoword = txtConfirmPassword.Text; comboType = cboType.Text; validateForm(); if (!isFormValidationOk) { return; } if (checkIfUserAlreadyExist()) { errorProvider1.SetError(txtUsername, null); errorProvider1.SetError(txtUsername, "User Already Registered,Please Enter New Username"); txtUsername.Focus(); return; } Encrypter encrypter = new Encrypter(); String conPass = encrypter.MD5Hash(txtPassword.Text); try { dbConn.executeQuery("INSERT INTO userdetails (userid, username, password, type, status) VALUES " + "(NULL, '" + textUsername + "','" + conPass + "', '" + comboType.ToLower() + "','active');"); MessageBox.Show("A New " + cboType.SelectedItem.ToString().ToUpper() + " has been Registered"); txtConfirmPassword.Clear(); txtPassword.Clear(); txtUsername.Clear(); } catch (Exception ex) { MessageBox.Show("" + ex.StackTrace); } }