private void simpleButton2_Click(object sender, EventArgs e)
        {
            string oldPass        = textEdit2.Text;
            string newPass        = textEdit3.Text;
            string newPassConfirm = textEdit4.Text;

            if (newPass != newPassConfirm)
            {
                XtraMessageBox.Show("Mật khẩu mới và xác nhận MK mới không giống nhau!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                string temp = HashString.MD5Hash(oldPass);
                if (user.password != temp)
                {
                    XtraMessageBox.Show("Mật khẩu cũ không đúng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    temp          = HashString.MD5Hash(newPass);
                    user.password = temp;
                    DataProvider.Ins.DB.Users.Add(user);
                    DataProvider.Ins.DB.Users.Attach(user);
                    DataProvider.Ins.DB.Entry(user).State = EntityState.Modified;
                    DataProvider.Ins.DB.SaveChanges();
                    XtraMessageBox.Show("Thay đổi mật khẩu thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }
        }
Exemplo n.º 2
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            string username = txbUsername.Text;
            string password = HashString.MD5Hash(txbPassword.Text);
            var    user     = DataProvider.Ins.DB.Users.FirstOrDefault(x => x.username == username);

            if (user != null && user.password == password)
            {
                this.Hide();
                MainForm mainForm = new MainForm(user);
                mainForm.FormClosed += mainFormClose;
                mainForm.Show();
            }
            else
            {
                XtraMessageBox.Show("Tên đăng nhập hoặc mật khẩu không hợp lệ!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            string username        = textEdit1.Text;
            string password        = textEdit3.Text;
            string passwordConfirm = textEdit4.Text;

            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password) || String.IsNullOrEmpty(passwordConfirm))
            {
                XtraMessageBox.Show("Tên người dùng hoặc mật khẩu chưa được điền!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                User user = DataProvider.Ins.DB.Users.FirstOrDefault(x => x.username == username);
                if (user != null)
                {
                    XtraMessageBox.Show("Tên người dùng đã tồn tại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    if (password != passwordConfirm)
                    {
                        XtraMessageBox.Show("Mật khẩu và xác nhận MK không giống nhau!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        user          = new User();
                        user.username = username;
                        user.password = HashString.MD5Hash(password);
                        user.role     = "admin";
                        DataProvider.Ins.DB.Users.Add(user);
                        DataProvider.Ins.DB.SaveChanges();
                        XtraMessageBox.Show("Thêm người dùng mới thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                }
            }
        }