Example #1
0
        private void signUpBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string userName        = userNameTextBox.Text;
            string password        = passwordTextBox.Text;
            string reEnterPassword = reEnterPasswordTextBox.Text;
            string firstName       = firstNameTextBox.Text;
            string lastName        = lastNameTextBox.Text;
            bool   isValidData     = DataHandler.isValidUserName(userName) &&
                                     DataHandler.isValidPassword(password, reEnterPassword) &&
                                     DataHandler.isValidName(firstName) &&
                                     DataHandler.isValidName(lastName);

            if (!isValidData)
            {
                MessageBox.Show("Some of the data is invalid. \n " +
                                "All fields are required and has to be 4 to 16 chars long chars and numbers",
                                "Please check form");
                return;
            }
            else if (!DataHandler.isUserNameFree(userName))
            {
                MessageBox.Show("User name is already taken by another user",
                                "Please try another user name");
                return;
            }

            DbAbstractionLayer.addNewUserToDb(userName, firstName, lastName, password);
            e.Result = userName;
        }
Example #2
0
        public static bool checkPassword(string userName, string password)
        {
            /* Fetch the stored value */
            string savedPasswordHash = DbAbstractionLayer.getUserHashedPassword(userName);             // DBContext.GetUser(u => u.UserName == user).Password;

            if (savedPasswordHash.Length == 0)
            {
                return(false);
            }
            /* Extract the bytes */
            byte[] hashBytes = Convert.FromBase64String(savedPasswordHash);
            /* Get the salt */
            byte[] salt = new byte[16];
            Array.Copy(hashBytes, 0, salt, 0, 16);
            /* Compute the hash on the password the user entered */
            var pbkdf2 = new Rfc2898DeriveBytes(password, salt, 100000);

            byte[] hash = pbkdf2.GetBytes(20);
            /* Compare the results */
            for (int i = 0; i < 20; i++)
            {
                if (hashBytes[i + 16] != hash[i])
                {
                    return(false);
                }
            }
            return(true);
        }
        private void AdminReportsForm_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = bindingSource1;
            List <string> users = DbAbstractionLayer.getAllUserNames();

            users.ForEach(delegate(String user)
            {
                usersComboBox.Items.Add(user);
            });
            usersComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
        }
Example #4
0
 public User(string userName, string password)
 {
     if (DataHandler.checkPassword(userName, password))
     {
         Dictionary <string, string> userDetails = DbAbstractionLayer.getUserDetails(userName);
         this.userName      = userDetails["userName"];
         this.userFirstName = userDetails["firstName"];
         this.userLastName  = userDetails["lastName"];
         this.accessLevel   = Int32.Parse(userDetails["accessLevel"]);
     }
 }
        private void searchButton_Click(object sender, EventArgs e)
        {
            string   userName = showAllUsersCheckBox.Checked ? "all" : usersComboBox.Text;
            DateTime?from = null, upTo = null;

            if (!fromAnyCheckBox.Checked)
            {
                from = fromDateTimePicker.Value;
            }
            if (!untilTodayCheckBox.Checked)
            {
                upTo = upToDateTimePicker.Value;
            }
            DbAbstractionLayer search = new DbAbstractionLayer(from, upTo, userName);

            bindingSource1.DataSource = search.searchResult;
            for (int i = 0; i <= dataGridView1.ColumnCount - 2; i++)
            {
                dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
            }
            dataGridView1.Columns[dataGridView1.ColumnCount - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
        }
Example #6
0
        private void showClockTimer_Tick(object sender, EventArgs e)
        {
            clockLabel.Text = DateTime.Now.ToLongTimeString();

            currentStatus.Text = $"Entered on: {DbAbstractionLayer.getOpenEntry(user.userName)}";
            if (DbAbstractionLayer.getOpenEntry(user.userName) != null)
            {
                setTimeStampButton.Text = "Log out";
                TimeSpan logDurtion = (TimeSpan)(DateTime.Now - DbAbstractionLayer.getOpenEntry(user.userName));
                string   days       = logDurtion.Days > 0 ? $"{logDurtion.Days} days and " : "";
                string   hours      = logDurtion.Hours < 10 ? $"0{logDurtion.Hours}" : $"{logDurtion.Hours}";
                string   minutes    = logDurtion.Minutes < 10 ? $"0{logDurtion.Minutes}" : $"{logDurtion.Minutes}";
                string   seconds    = logDurtion.Seconds < 10 ? $"0{logDurtion.Seconds}" : $"{logDurtion.Seconds}";
                currentSession           = $"{days} {hours}h:{minutes}m:{seconds}s";
                loggedDurationLabel.Text = currentSession;
            }
            else
            {
                setTimeStampButton.Text  = "Log in";
                currentStatus.Text       = "Currently not logged in";
                loggedDurationLabel.Text = currentSession != "" ? $"you were logged for:\n {currentSession}" : "";
            }
        }
Example #7
0
        private void setTimeStampButton_Click(object sender, EventArgs e)
        {
            string type = DbAbstractionLayer.getOpenEntry(user.userName) != null ? "exit" : "entry";

            DbAbstractionLayer.setTimeStamp(user.userName);
        }
Example #8
0
        public static bool isUserNameFree(string userName)
        {
            List <string> users = DbAbstractionLayer.getAllUserNames();

            return(!users.Contains(userName));
        }
Example #9
0
 private void setTablesBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     DbAbstractionLayer.setUpUsersTable();
     DbAbstractionLayer.setUpEntryLogTable();
 }