예제 #1
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (txtReason.Text != "")
            {
                var crashType = "Software";
                if (radioSystem.Checked == true)
                {
                    crashType = "System";
                }

                var query = db.UserLogins.Find(loginID);
                query.Reason    = txtReason.Text;
                query.CrashType = crashType;

                db.SaveChanges();

                if (db.Users.Where(x => x.ID == userID).Select(x => x.RoleID).ToArray()[0] == 1)
                {
                    this.Hide();
                    var mainForm = new AdminMainForm();
                    mainForm.userID = userID;
                    mainForm.Show();
                }
                else
                {
                    this.Hide();
                    var mainForm = new UserMainForm();
                    mainForm.userID = userID;
                    mainForm.Show();
                }
            }
            else
            {
                MessageBox.Show("Please fill up all fields ...");
            }
        }
예제 #2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUsername.Text != "" && txtPassword.Text != "")
            {
                var cekPassword = db.Users.Where(x => x.Email == txtUsername.Text).ToList();
                if (cekPassword.Count > 0)
                {
                    var md5            = new MD5CryptoServiceProvider();
                    var bytes          = md5.ComputeHash(new UTF8Encoding().GetBytes(txtPassword.Text));
                    var hashedPassword = "";
                    for (int i = 0; i < bytes.Length; i++)
                    {
                        hashedPassword += bytes[i].ToString("x2");
                    }

                    if (hashedPassword == cekPassword[0].Password)
                    {
                        if (cekPassword[0].Active == true)
                        {
                            var userID       = cekPassword[0].ID;
                            var cekLastLogin = db.UserLogins.Where(x => x.UserID == userID).OrderByDescending(x => x.LoginTime).ToList();

                            if (cekLastLogin.Count() > 0)
                            {
                                if (cekLastLogin[0].LogoutTime == null)
                                {
                                    this.Hide();
                                    var crash = new CrashForm();
                                    crash.loginID = cekLastLogin[0].ID;
                                    crash.userID  = userID;

                                    crash.Show();
                                }
                                else
                                {
                                    if (cekPassword[0].RoleID == 1)
                                    {
                                        this.Hide();
                                        var mainForm = new AdminMainForm();
                                        mainForm.userID = userID;
                                        mainForm.Show();
                                    }
                                    else
                                    {
                                        this.Hide();
                                        var mainForm = new UserMainForm();
                                        mainForm.userID = userID;
                                        mainForm.Show();
                                    }
                                }
                            }
                            else
                            {
                                if (cekPassword[0].RoleID == 1)
                                {
                                    this.Hide();
                                    var mainForm = new AdminMainForm();
                                    mainForm.userID = userID;
                                    mainForm.Show();
                                }
                                else
                                {
                                    this.Hide();
                                    var mainForm = new UserMainForm();
                                    mainForm.userID = userID;
                                    mainForm.Show();
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Sorry, you are disabled to login ...");
                        }
                    }
                    else
                    {
                        wrongLoginCount++;

                        if (wrongLoginCount > 3)
                        {
                            MessageBox.Show("You have entered wrong login credentials for more than 3 times\nWait for the countdown to try logging in again ...");
                            lblTimer.Visible = true;
                            lblTimer.Text    = "Login Countdown : " + loginCountdown;
                            timer.Start();
                        }
                        else
                        {
                            MessageBox.Show("Username or password is wrong ...");
                        }
                    }
                }
                else
                {
                    wrongLoginCount++;

                    if (wrongLoginCount > 3)
                    {
                        MessageBox.Show("You have entered wrong login credentials for more than 3 times\nWait for the countdown to try logging in again ...");
                        lblTimer.Visible = true;
                        lblTimer.Text    = "Login Countdown : " + loginCountdown;
                        timer.Start();
                    }
                    else
                    {
                        MessageBox.Show("Username or password is wrong ...");
                    }
                }
            }
            else
            {
                MessageBox.Show("Please fill up all fields ...");
            }
        }