Example #1
0
        private void btn_changepasswd1_Click(object sender, EventArgs e)
        {
            con.Open();
            string query = "select Passwd from nguoidung where Username = '******'";
            //Truy vần với Passwd trong bảng "nguoidung" tại Username trong dữ liệu SQL
            SqlCommand    cmd    = new SqlCommand(query, con);
            SqlDataReader reader = cmd.ExecuteReader();

            reader.Read();
            String pass = reader[0].ToString();

            con.Close();
            if (txt_currentpswd.Text.Equals(pass))                                   //kiểm tra so sánh Passwd được nhập chính xác chưa.
            {
                if (txt_newpswd.Text.ToString().Equals(txt_repsswd.Text.ToString())) //nếu chính xác thì yêu cầu nhập passwd mới ở trường txt_newpswd và đồng thời phải nhập lại passwd xác nhập ở trường repaswd.
                {
                    con.Open();
                    query = "update nguoidung set Passwd = '" + txt_newpswd.Text.ToString() + "' " + "where Username = '******'";
                    //Passwd nhập chính xác ở 2 trường txt_newpswd và tx_repsswd thì update bảng "nguoidung" với Passwd mới vừa nhập tại Username đã đăng nhập.
                    cmd = new SqlCommand(query, con);
                    cmd.ExecuteNonQuery();
                    con.Close();
                    MessageBox.Show("Cập nhật mật khẩu mới thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    login lg = new login();
                    lg.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Mật khẩu mới không khớp !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Mật khẩu hiện tại không đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
 private void SendCallback(object sender, AsyncCompletedEventArgs e)
 {
     if (e.Cancelled)
     {
         MessageBox.Show(string.Format("Email bị hủy: {0}", e.UserState));
     }
     if (e.Error != null)
     {
         MessageBox.Show(string.Format("Có lỗi khi gửi! Xem lại đường truyền: {0}", e.UserState));
     }
     else
     {
         //Nếu gửi mail thành công thì mới ghi password mới xuống CSDL
         con.Open();
         MessageBox.Show("Email đã gửi thành công!");
         string     str = "update nguoidung set Passwd='" + rand.ToString() + "' where Username='******'";
         SqlCommand cmd = new SqlCommand(str, con);
         cmd.ExecuteNonQuery();
         con.Close();
         login lg = new login();
         lg.Show();
         this.Hide();
     }
 }
Example #3
0
        private void sign_up_FormClosing(object sender, FormClosingEventArgs e)
        {
            login lg = new login();

            lg.Close();
        }
Example #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Equals("") || textBox2.Text.Equals("") || txt_email4.Text.Equals("")) //Kiểm tra một trong các trường trong form đăng kí mà bỏ trống. thì yêu cầu nhập đầy đủ thông tin.
            {
                MessageBox.Show("Vui lòng điền đầy đủ thông tin!");
                return;
            }
            else if (!kiemtraTen(textBox1.Text))// yêu cầu user nhập vào phải thuộc quy ước trong hàm "kiemtraTen".
            {
                return;
            }
            else if (!kiemtraPasswd(textBox2.Text.ToString()))// yêu cầu passwd nhập vào phải thuộc theo quy ước của hàm "kiemtraPasswd".
            {
                return;
            }
            else if (!kiemtraEmail(txt_email4.Text.ToString()))//yêu cầu Email nhập vào phải thuộc theo quy ước của hàm "kiemtraEmail".
            {
                return;
            }
            else
            {
                if (!textBox2.Text.ToString().Equals(textBox3.Text.ToString()))//nếu passwd nhập vào và passwd xác nhập không trùng sẽ báo lỗi. Và không cho đăng ký.
                {
                    MessageBox.Show("Mật khẩu nhập lại không đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                try
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                        String        query  = "select Username from nguoidung where Username = '******'";//truy vấn Username từ bảng "nguoidung" ở Username trong dữ liệu SQL.
                        SqlCommand    cmd1   = new SqlCommand(query, con);
                        SqlDataReader reader = cmd1.ExecuteReader();
                        String        user   = "";

                        while (reader.Read())
                        {
                            user = reader[0].ToString();//Đọc dữ liệu từng dòng trên dữ liệu SQL trong while()
                        }
                        //reader.Read();
                        //count = reader[0].ToString();
                        con.Close();
                        if (textBox1.Text.Equals(user))//kiểm tra nếu username vửa tạo mà đã có trong dữ liệu SQL thì sẽ báo lỗi. Yêu cầu nhập lại username.
                        {
                            MessageBox.Show("Tài khoản đã tồn tại! Vui lòng tạo tài khoản khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else if (!kiemtraTen(textBox1.Text))//Ngoài ra cũng đồng thời kiểm tra username đó phải thuộc quy ước trong hàm "kiemtraTen".
                        {
                            return;
                        }
                    }
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                        String query = "select Email from nguoidung where Email = '" + txt_email4.Text.ToString() + "'";
                        //truy vấn Email từ bảng "nguoidung" ở Email trong dữ liệu SQL.
                        SqlCommand    cmd2   = new SqlCommand(query, con);
                        SqlDataReader reader = cmd2.ExecuteReader();
                        String        count1 = "";

                        while (reader.Read())
                        {
                            count1 = reader[0].ToString();//Đọc dữ liệu từng dòng trên dữ liệu SQL trong while()
                        }
                        //reader.Read();
                        //count = reader[0].ToString();
                        con.Close();
                        if (txt_email4.Text.Equals(count1))//kiểm tra nếu Email vửa tạo mà đã có trong dữ liệu SQL thì sẽ báo lỗi. Yêu cầu nhập lại Email.
                        {
                            MessageBox.Show("Email đã tồn tại! Vui lòng tạo tài khoản khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        con.Close();
                    }

                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }
                    String str = "insert into nguoidung(Username,Passwd,Email) values ('" + textBox1.Text + "', '" + textBox2.Text + "','" + txt_email4.Text + "')";
                    //Thêm vào bảng "nguoidung" với Username,Passwd,Email với giá trị tương ứng với từng trường trong form đăng kí. Đã kiểm tra tất cả điều kiện, đúng mới thêm vào được trong dữ liệu SQL.
                    //insert into nguoidung(Username, Passwd) values('thuongvt', '12345')
                    string str2 = "select count(*) from nguoidung where Username='******'and Passwd='" + textBox2.Text + "'and Email='" + txt_email4.Text + "'";
                    //Truy vấn trong bảng "nguoidung" với Username,Passwd,Email có dòng thoải điều kiện trong bảng không.
                    SqlCommand cmd = new SqlCommand(str, con);
                    cmd.ExecuteNonQuery();

                    SqlDataAdapter sqldata = new SqlDataAdapter(str2, con);
                    DataTable      dtbl    = new DataTable();
                    sqldata.Fill(dtbl);
                    if (dtbl.Rows[0][0].ToString() == "1")//nếu thoải điều kiện thì cho đăng kí đồng thời mở lại form login.
                    {
                        MessageBox.Show("Đăng ký thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        login frm2 = new login();
                        frm2.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("Vui lòng điền đầy đủ thông tin!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    if (con.State == ConnectionState.Open)
                    {
                        con.Close();
                        return;
                    }
                }
                catch
                {
                    MessageBox.Show("Đăng ký thất bại !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #5
0
        private void sign_up_FormClosed(object sender, FormClosedEventArgs e)//Form sign_up đóng thì form login đồng thời được gọi lên.
        {
            login lg = new login();

            lg.Close();
        }