private void submit_Click(object sender, EventArgs e)
        {
            if (userName.Text.Equals("") || email.Text.Equals(""))
            {
                CheckValid(userName);
                CheckValid(email);
            }
            else
            {
                // build query to check if user exists
                StringBuilder queryId = new StringBuilder();
                queryId.Append("SELECT COUNT(*) FROM TAIKHOAN WHERE USERNAME LIKE '");
                queryId.Append(userName.Text);
                queryId.Append("'");

                // create connection
                SqlConnection conn = new SqlConnection(Program.getConnectionString());
                SqlCommand    cmd  = conn.CreateCommand();
                cmd.CommandText = queryId.ToString();

                // execute command
                conn.Open();
                String count = Convert.ToString(cmd.ExecuteScalar());
                conn.Close();

                if (count.Equals("0"))
                {
                    MaterialMessageBox.Show("Không tìm thấy username hãy thử lại", "Thông báo");
                    userName.Focus();
                }
                else
                {
                    // build a random password
                    StringBuilder passBuilder = new StringBuilder();
                    passBuilder.Append(RandomString(4, true));
                    passBuilder.Append(new Random().Next(1000, 9999));
                    passBuilder.Append(RandomString(2, false));

                    // build query to set new password
                    StringBuilder query = new StringBuilder();
                    query.Append("UPDATE TAIKHOAN SET PWD = '");
                    query.Append(passBuilder);
                    query.Append("'");
                    query.Append("WHERE USERNAME LIKE '");
                    query.Append(userName.Text);
                    query.Append("'");

                    // create new query for command
                    cmd.CommandText = query.ToString();

                    // open connection
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();

                    // create mail message
                    MailMessage msg = new MailMessage();
                    msg.From = new MailAddress("*****@*****.**");
                    msg.To.Add(email.Text);
                    msg.Subject    = "[RECOVER PASSWORD]";
                    msg.Body       = ("userName : "******"<br>" + "Recovery password: "******"smtp.gmail.com";

                    // create Network Credential
                    NetworkCredential ntwd = new NetworkCredential();
                    ntwd.UserName = "******";
                    ntwd.Password = "******";

                    // set specification for smtp client
                    smt.UseDefaultCredentials = true;
                    smt.Credentials           = ntwd;
                    smt.Port      = 587;
                    smt.EnableSsl = true;
                    smt.Send(msg);

                    MaterialMessageBox.Show("Mật khẩu khôi phục đã được gửi", "Thông báo");
                    this.Close();
                }
            }
        }
        private void submit_Click(object sender, EventArgs e)
        {
            if (oldPassword.Text.Equals("") || newPassword.Text.Equals("") || newPasswordConfirm.Text.Equals(""))
            {
                MessageBox.Show("Bạn chưa điền đủ thông tin vui lòng kiểm tra!");
                checkFocus(oldPassword);
                checkFocus(newPassword);
                checkFocus(newPasswordConfirm);
            }
            else
            {
                StringBuilder query = new StringBuilder();
                query.Append("SELECT COUNT(*) FROM TAIKHOAN WHERE USERNAME LIKE '");
                query.Append(userName);
                query.Append("'");
                query.Append("AND PWD LIKE '");
                query.Append(oldPassword.Text);
                query.Append("'");

                SqlConnection conn = new SqlConnection(Program.getConnectionString());
                SqlCommand    cmd  = conn.CreateCommand();
                cmd.CommandText = query.ToString();

                conn.Open();
                String count = Convert.ToString(cmd.ExecuteScalar());
                conn.Close();

                if (count.Equals("0"))
                {
                    MaterialMessageBox.Show("Sai mật khẩu ☻", "Thông báo");
                }
                else
                {
                    if (oldPassword.Text.Equals(newPassword.Text))
                    {
                        MaterialMessageBox.Show("Bạn nhập 2 mật khẩu trùng nhau", "Thông báo");
                    }
                    else
                    {
                        if (newPassword.Text.Equals(newPasswordConfirm.Text))
                        {
                            cmd.CommandText = "EXEC SP_CHANGEPASSWORD @OLDPASSWORD , @NEWPASSWORD , @USERNAME ";
                            cmd.Parameters.Add("@OLDPASSWORD", SqlDbType.VarChar, 100).Value = oldPassword.Text.ToString();
                            cmd.Parameters.Add("@NEWPASSWORD", SqlDbType.VarChar, 100).Value = newPassword.Text.ToString();
                            cmd.Parameters.Add("@USERNAME", SqlDbType.VarChar, 100).Value    = userName;

                            conn.Open();
                            cmd.ExecuteNonQuery();
                            conn.Close();

                            // clear field
                            oldPassword.Text        = "";
                            newPassword.Text        = "";
                            newPasswordConfirm.Text = "";
                            this.Close();

                            MaterialMessageBox.Show("Mật khẩu đã được đổi", "Thông báo");
                        }
                    }
                }
            }
        }