private void Button1_Click(object sender, EventArgs e) { try { Felhasznalo f = new Felhasznalo(Titkositasok.SHAHash(textBox1.Text.Trim() + Konstans.salt), Titkositasok.SHAHash(textBox2.Text + Konstans.salt), ""); if (!ABKezelo.SikeresBelepes(f)) { throw new WarningException("Unsuccessful login!"); } ABKezelo.setCurrentUser(f); Logolas.Ment("Successful login, name: " + textBox1.Text.Trim()); } catch (Exception ex) { if (ex is WarningException) { MessageBox.Show(ex.Message, "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } DialogResult = DialogResult.None; } }
private void Button1_Click(object sender, EventArgs e) { int l1 = textBox1.Text.Trim().Length; int l2 = textBox2.Text.Length; if (l1 < 4 || l1 > 24) { MessageBox.Show("User name's length should be between 4 and 24 !", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; } else if (textBox2.Text != textBox3.Text) { MessageBox.Show("The two passwords should be the same!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; } else if (l2 < 4 || l2 > 24) { MessageBox.Show("Password length should be between 4 and 24 !", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; } else if (textBox4.Text.Length > 30) { MessageBox.Show("Password remainder should be at most 30 !", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; } else { Titkositasok t = new Titkositasok(); string felhasznaloNevHash = Titkositasok.SHAHash(textBox1.Text.Trim() + Konstans.salt); if (ABKezelo.CountUsers(felhasznaloNevHash) > 0) { MessageBox.Show("This username is already registered, choose another one!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; } else { string jelszoHash = Titkositasok.SHAHash(textBox2.Text + Konstans.salt); Felhasznalo f = new Felhasznalo(felhasznaloNevHash, jelszoHash, t.f0(felhasznaloNevHash, textBox4.Text, KodolasIranya.Kódol)); ABKezelo.Beszuras(f); Logolas.Ment("Register a new user, the name: " + textBox1.Text.Trim()); } } }