コード例 #1
0
ファイル: HomeUserCtrl.cs プロジェクト: eddiechow/unika
        private void showLoginLog()
        {
            SupplierLoginLogDA slda = new SupplierLoginLogDA();
            List <LoginLog>    list = slda.searchLogs(null, null, supplierID, null, conn);

            for (int i = list.Count - 1; i >= 0; i--)
            {
                loginLogDataGridView.Rows.Add(
                    list.ElementAt(i).getTime(),
                    list.ElementAt(i).getStatus());
            }
        }
コード例 #2
0
        private void supplierSearchButton_Click(object sender, EventArgs e)
        {
            supplierLoginLogGridView.Rows.Clear();
            supplierLoginLogGridView.Refresh();

            DateTime start = searchSupplierStartDateTime.Value.Date;
            DateTime end   = searchSupplierEndDateTime.Value.Date.AddDays(1).AddMilliseconds(-1);

            List <LoginLog> suploginloglist = slda.searchLogs(start, end, (string.IsNullOrWhiteSpace(supplierIDTextBox.Text)) ? null : supplierIDTextBox.Text, (string.IsNullOrWhiteSpace(supplierNameTextBox.Text)) ? null : supplierNameTextBox.Text, conn);

            for (int i = suploginloglist.Count - 1; i >= 0; i--)
            {
                supplierLoginLogGridView.Rows.Add(suploginloglist.ElementAt(i).getTime(), suploginloglist.ElementAt(i).getAccountID(), suploginloglist.ElementAt(i).getAccountName(), suploginloglist.ElementAt(i).getStatus());
            }

            resetButton.PerformClick();
        }
コード例 #3
0
ファイル: LoginForm.cs プロジェクト: eddiechow/unika
        private void loginButton_Click(object sender, EventArgs e)
        {
            try
            {
                SupplierDA         sda  = new SupplierDA();
                Supplier           sup  = sda.getOneSupplierByID(idTextbox.Text, conn);
                SupplierLoginLogDA slda = new SupplierLoginLogDA();

                if (!string.IsNullOrWhiteSpace(idTextbox.Text) && !string.IsNullOrEmpty(passwordTextbox.Text))
                {
                    if (!string.IsNullOrWhiteSpace(sup.getSupplierID()) && !string.IsNullOrWhiteSpace(sup.getPassword()))
                    {
                        List <LoginLog> logs = slda.searchLogs(DateTime.Now.AddHours(-0.5), DateTime.Now, sup.getSupplierID(), "", conn);

                        bool     isLocked     = false;
                        DateTime?unlockedTime = null;
                        for (int i = 0; i < logs.Count; i++)
                        {
                            if (logs.ElementAt(i).getLocked())
                            {
                                isLocked = true;
                            }
                            if (!string.IsNullOrEmpty(logs.ElementAt(i).getUnlockedByEmpID()))
                            {
                                isLocked     = false;
                                unlockedTime = logs.ElementAt(i).getTime();
                            }
                        }

                        if (isLocked)
                        {
                            LoginLog ll = new LoginLog();
                            ll.setAccountID(sup.getSupplierID());
                            ll.setSuccess(false);
                            ll.setPasswordIncorrect(false);
                            ll.setLocked(false);
                            ll.setAcStatusTempLock(true);
                            ll.setTime(DateTime.Now);
                            slda.insert(ll, conn);
                            MessageBox.Show(rs.GetString("accountLockedMsg"), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            if (unlockedTime.HasValue)
                            {
                                logs = null;
                                logs = slda.searchLogs(unlockedTime.Value.AddMinutes(1), DateTime.Now, sup.getSupplierID(), "", conn);
                            }

                            if (sup.getSupplierID().Equals(idTextbox.Text) && Security.verifyHash(passwordTextbox.Text, "SHA512", sup.getPassword()))
                            {
                                LoginLog ll = new LoginLog();
                                ll.setAccountID(sup.getSupplierID());
                                ll.setSuccess(true);
                                ll.setPasswordIncorrect(false);
                                ll.setLocked(false);
                                ll.setAcStatusTempLock(false);
                                ll.setTime(DateTime.Now);
                                slda.insert(ll, conn);

                                for (int i = 0; i < formList.Length; i++)
                                {
                                    if (sup.getProductCategory().Equals(formList[i][0]))
                                    {
                                        Visible              = false;
                                        mainForm             = (Form)Activator.CreateInstance(Type.GetType(GetType().Namespace + "." + formList[i][1] + ".MainForm"), sup.getSupplierID());
                                        mainForm.FormClosed += new FormClosedEventHandler(mainForm_Closed);
                                        showStockAlert(sup.getSupplierID(), sup.getProductCategory());
                                        showRecycleBinAlert(sup.getSupplierID(), sup.getProductCategory());
                                        mainForm.ShowDialog();
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                int attempts = 1;
                                for (int i = 0; i <= logs.Count; i++)
                                {
                                    if (i < logs.Count)
                                    {
                                        if (logs.ElementAt(i).getPasswordIncorrect())
                                        {
                                            if (attempts == 4)
                                            {
                                                LoginLog ll = new LoginLog();
                                                ll.setAccountID(sup.getSupplierID());
                                                ll.setSuccess(false);
                                                ll.setPasswordIncorrect(true);
                                                ll.setLocked(true);
                                                ll.setAcStatusTempLock(false);
                                                ll.setTime(DateTime.Now);
                                                slda.insert(ll, conn);
                                                MessageBox.Show(rs.GetString("accountLock30MinMsg"), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                break;
                                            }
                                            attempts++;
                                        }
                                        else if (logs.ElementAt(i).getSuccess())
                                        {
                                            attempts = 1;
                                        }
                                    }
                                    else if (i == logs.Count)
                                    {
                                        LoginLog ll = new LoginLog();
                                        ll.setAccountID(sup.getSupplierID());
                                        ll.setSuccess(false);
                                        ll.setPasswordIncorrect(true);
                                        ll.setLocked(false);
                                        ll.setAcStatusTempLock(false);
                                        ll.setTime(DateTime.Now);
                                        slda.insert(ll, conn);
                                        MessageBox.Show(rs.GetString("idPasswdIncorrectMsg"), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(rs.GetString("idPasswdIncorrectMsg"), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show(rs.GetString("inputIdPasswordMsg"), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                idTextbox.Text       = "";
                passwordTextbox.Text = "";
            }
            catch (MySqlException ex)
            {
                Database.showErrorMessage(ex.Number);
            }
            catch (Exception)
            {
                MessageBox.Show("System error.\nPlease contact administrator.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.ExitThread();
            }
        }