Exemplo n.º 1
0
 public MainMenu_Form(User u)
 {
     InitializeComponent();
     currentUser = u;
     currentShift = u.GetOpenShift();
     InitializeFormElements();
     this.Size = DEFAULT_SIZE;
     numVehicle.Value = currentUser.LastVehicleUsed();
 }
Exemplo n.º 2
0
        public static User Login(string username, string password)
        {
            // Pass password as plaintext
            log = new Logger(LOG_FILE);

            string stm = String.Format("SELECT password FROM T_CREDENTIALS WHERE username = '******'", username);

            var row = DatabaseConnection.ExecuteScalar(stm);

            if (row != null)
            {
                string retrievedPassword = row.ToString();
                string hashedInputPassword = Secure.Hash(password);
                if (retrievedPassword.Equals(hashedInputPassword))
                {
                    // Access granted
                    DataTable userInformationTable;

                    stm = String.Format(@"SELECT T_USER.id, T_USER.name, T_USER.address, T_USER.sin, T_USER.bank_account, T_USER.wage
                                        FROM T_USER
                                        INNER JOIN T_CREDENTIALS
                                        ON T_USER.id = T_CREDENTIALS.user_id
                                        WHERE T_CREDENTIALS.username = '******'", username);

                    userInformationTable = DatabaseConnection.ExecuteSelect(stm);

                    User ret = new User(Convert.ToInt32(userInformationTable.Rows[0][0]),
                        userInformationTable.Rows[0][1].ToString(),
                        userInformationTable.Rows[0][2].ToString(),
                        Convert.ToInt32(userInformationTable.Rows[0][3]),
                        userInformationTable.Rows[0][4].ToString(),
                        Convert.ToDouble(userInformationTable.Rows[0][5]));

                    return ret;
                }
                else
                {
                    // Access denied
                    log.Write(String.Format("{0} failed login request with password: {1}", username.ToUpper(), password));
                    return null;
                }
            }
            else
            {
                // User doesn't exist
                log.Write(String.Format("{0} attempted login, but user does not exist", username.ToUpper()));
                return null;
            }
        }
Exemplo n.º 3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            User current = User.Login(txtUsername.Text.ToString(), txtPassword.Text.ToString());

            if(current != null)
            {
                currentUser = current;
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("Oops! We didn't recognize that username/password. Please try again.");
                txtPassword.Text = "";
            }
        }
Exemplo n.º 4
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            initLogger();
            CheckDatabase();
            if (DEBUG_MODE) { SeedDebugDatabase(); }

            Login_Form loginForm = new Login_Form();

            if (loginForm.ShowDialog() == DialogResult.OK)
            {
                currentUser = loginForm.currentUser;
                Application.Run(new MainMenu_Form(currentUser));
            }
            else
            {
                Application.Exit();
            }
        }
Exemplo n.º 5
0
        private void LogOutAndReopen()
        {
            Login_Form loginForm = new Login_Form();

            this.Visible = false;
            mainMenuOpen = false;

            if (loginForm.ShowDialog() == DialogResult.OK)
            {
                currentUser = loginForm.currentUser;
                currentShift = currentUser.GetOpenShift();
                lastShift = null;
                InitializeFormElements();
                this.Visible = true;
                chkVehicleLocked.Checked = true;

                if (btnReview.Visible == false)
                {
                    this.Size = DEFAULT_SIZE;
                    lblLastShift.Visible = false;
                    lblLastShiftInformation.Visible = false;
                    btnCloseReviewShifts.Visible = false;
                    btnMoreShiftInformation.Visible = false;
                    btnReview.Visible = true;
                }
                mainMenuOpen = true;
            }
            else
            {
                Application.Exit();
            }
        }