Example #1
0
        //NIEUWE USER REGISTREREN
        private void btnRegister_Click_1(object sender, EventArgs e)
        {
            //Registratievenster opent
            FormRegister rf = new FormRegister(this);

            rf.ShowDialog();

            //Als user succesvol gemaakt is (in registratievenster), verschijnt deze tekst in label
            if (userCreated)
            {
                lblNotification.ForeColor = Color.Green;
                lblNotification.Font      = new Font(lblNotification.Font, FontStyle.Bold);
                lblNotification.Text      = "The user is created successfully!";
            }

            //Als max aantal users bereikt is, verschijnt deze tekst
            CountUsers();
            if (maxUsersReached)
            {
                btnRegister.Enabled = false;
                lblNote.Visible     = true;
                lblNote2.Visible    = true;
            }

            //Textboxes worden terug leeggemaakt
            txtUsername.Clear();
            txtPassword.Clear();
        }
Example #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string username       = txtUsername.Text;
            string password       = txtPassword.Text;
            bool   userExists     = false;
            string salt           = "";
            string hashedPassword = "";
            string hashControl    = "";

            try
            {
                //user.login-file openen en lijn inlezen
                input = File.OpenText(path + "/user.login");
                line  = input.ReadLine();
                char     separator = ',';
                string[] words;

                //salt en hash bepalen van users in bestand
                while (line != null && !userExists)
                {
                    lineCounter++;
                    words = line.Split(separator);

                    if (words[0] == username)
                    {
                        userExists = true;

                        salt           = words[1];
                        hashedPassword = words[2];

                        byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
                        byte[] saltBytes     = Encoding.UTF8.GetBytes(salt);
                        hashControl = PasswordStorage.HashPassword(passwordBytes, saltBytes, 50000); //Maakt nieuwe hash om te controleren
                    }
                    else
                    {
                        line = input.ReadLine();
                    }

                    input.Close();
                }
            }
            catch (IOException)
            {
                MessageBox.Show("Close the 'user.login'-file before logging in.", "'user.login'-file is open.");
                return;
            }

            if (!userExists)
            {
                lbl1.Text = "This user does not exist.";
                lbl2.Text = "";
                return;
            }

            if (hashedPassword != hashControl)
            {
                lbl1.Text = "The password is incorrect.";
                lbl2.Text = "";
                return;
            }
            else
            {
                DeleteUser(username);

                FormRegister regForm = new FormRegister(lf);
                regForm.Show();

                this.Hide();
            }
        }