예제 #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");
                    }
                }
            }
        }
예제 #2
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (popup)
            {
                return;
            }
            string phone    = this.phone.Text;
            string password = this.password.Text;

            if (phone.Length != 11)
            {
                MessageBox.Show("Invalid phone");
            }
            else
            {
                try
                {
                    var reader = Db.Read("SELECT id, username, phone, password FROM teachers WHERE phone=" +
                                         Db.ValuesBuilder(new List <string>()
                    {
                        phone
                    }));
                    reader.Read();
                    var user = new
                    {
                        username = reader["username"],
                        phone    = reader["phone"],
                        password = reader["password"],
                        id       = reader["id"]
                    };
                    reader.Close();

                    var valid = SecurePasswordHasher.Verify(password, user.password.ToString());

                    Console.WriteLine(valid.ToString());
                    if (valid)
                    {
                        string     username = user.username.ToString();
                        schooldata sd       = new schooldata(username, user.id.ToString(), phone);
                        sd.Show();
                        Hide();
                    }
                    else
                    {
                        MessageBox.Show("Invalid password please try again");
                        this.password.Focus();
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Teacher not exists");
                }
            }
        }