Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string phone    = this.phone.Text;
            string password = this.password.Text;
            string errors   = "";

            if (phone.Trim().Length != 11)
            {
                errors += "Invalid phone number\n";
            }

            if (password.Trim().Length < 6)
            {
                errors += "Invalid password\n";
            }

            if (errors.Trim().Length > 0)
            {
                MessageBox.Show(errors);
            }
            else
            {
                var reader = Db.Read("SELECT secret FROM teachers WHERE phone=" +
                                     Db.ValuesBuilder(new List <string>()
                {
                    phone
                }));
                bool r = false;
                if (reader != null)
                {
                    reader.Read();
                    r = SecurePasswordHasher.Verify(secret.Text, reader["secret"].ToString());
                }
                reader.Close();

                if (r)
                {
                    bool res = Db.Mutation("UPDATE teachers set password = "******"WHERE phone = " + Db.ValuesBuilder(new List <string>()
                    {
                        phone
                    }));
                    if (res)
                    {
                        MessageBox.Show("successfully changed password");
                        Form1.popup = false;
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("something went wrong while changing password");
                    }
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string username = this.username.Text;
            string phone    = this.phone.Text;
            string password = this.password.Text;
            string secret   = this.secret.Text;
            string errors   = "";

            if (username.Trim().Length < 2)
            {
                errors += "Username min length is 2\n";
            }

            if (password.Trim().Length < 6)
            {
                errors += "Password too short\n";
            }

            if (phone.Trim().Length != 11)
            {
                errors += "Invalid phone number\n";
            }

            if (secret.Trim().Length < 1)
            {
                errors += "Secret min length is 1\n";
            }

            if (errors.Trim().Length > 0)
            {
                MessageBox.Show(errors);
            }
            else
            {
                var res = Db.Mutation("INSERT INTO teachers(username, phone, password, secret) VALUES(" +
                                      Db.ValuesBuilder(new List <string>()
                {
                    username,
                    phone,
                    SecurePasswordHasher.Hash(password),
                    SecurePasswordHasher.Hash(secret)
                })
                                      + ")");

                if (res)
                {
                    MessageBox.Show("Successfully create new user");
                    Form1.popup = false;
                    Close();
                    return;
                }

                MessageBox.Show("Something went wrong please try again later");
            }
        }