private void btnSave_Click(object sender, EventArgs e) { if (tbNewPassword.Text == tbNewPassword2.Text) { try { if (Crypto.CompareHash(tbOldPassword.Text, DbAction.GetPasswordByUser(credentials.email))) { var serverSidePass = cbBackUpPassword.Checked ? tbNewPassword2.Text : string.Empty; var hushPuppy = Crypto.MakeHash(tbNewPassword2.Text); ServerAction.ChangePassword(credentials.email, tbOldPassword.Text, serverSidePass); DbAction.ChangePassword(credentials.email, hushPuppy); credentials.password = hushPuppy; Close(); } else { throw new Internals.UnauthorizedAccessException("Wrong Username/Password"); } } catch (Exception ex) { lblError.Text = ex.Message; lblError.Visible = true; } } else { lblError.Text = "Passwords don't match"; lblError.Visible = true; } }
private void btnLogIn_Click(object sender, EventArgs e) { try { var Password = mtbPassword.Text; string dbPassword = string.Empty; var TbUsername = tbUsername.Text; if (DbAction.IsUsernameInDatabase(TbUsername)) { dbPassword = DbAction.GetPasswordByUser(TbUsername); } else { var SrvrSidePass = ServerAction.GetServerSidePass(TbUsername, Password); if (SrvrSidePass != string.Empty) { try { if (DbAction.AddNewUser(TbUsername, SrvrSidePass)) { throw new DatabaseConnectionFailure("Error inserting data into Database!"); } } catch (DatabaseConnectionFailure error) { MessageBox.Show(error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { lblInfo.Text = "Wrong Username/Password"; lblInfo.Visible = true; } } if (Crypto.CompareHash(Password, dbPassword)) { Hide(); frm_main frm_Main = new frm_main(tbUsername.Text, dbPassword); frm_Main.FormClosed += (s, args) => Close(); frm_Main.Show(); } else { throw new Internals.UnauthorizedAccessException("Wrong Username/Password"); } } catch (Internals.UnauthorizedAccessException error) { MessageBox.Show(error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }