Beispiel #1
0
        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());
                }
            }
        }
Beispiel #2
0
        private void Button2_Click(object sender, EventArgs e)
        {
            try
            {
                string felhasznaloNevHash = Titkositasok.SHAHash(textBox1.Text.Trim() + Konstans.salt);
                if (ABKezelo.CountUsers(felhasznaloNevHash) != 0)
                {
                    string       jelszoEmlekeztetoOTP = ABKezelo.getJelszoHash(felhasznaloNevHash);
                    Titkositasok t      = new Titkositasok();
                    string       jelszo = t.f0(felhasznaloNevHash, jelszoEmlekeztetoOTP, KodolasIranya.Dekódol);

                    if (jelszo != "" && jelszo[0] != 0)
                    {
                        MessageBox.Show("The password remainder: " + jelszo, "Information", MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    else
                    {
                        throw new WarningException("There is no such username or not set password remainder!");
                    }
                }
                else
                {
                    throw new WarningException("There is no such username or not set password remainder!");
                }
            }
            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);
                }
            }
        }