Exemple #1
0
        public bool VerifieerGebruiker(string _gebruikersnaam, string _wachtwoord)
        {
            EncryptieController ecr = new EncryptieController();
            string sha512Wachtwoord = ecr.encrypt(_wachtwoord);

            try
            {
                conn.Open();
                string         query               = "SELECT * FROM gebruiker WHERE gebruikersnaam = @gebruikersnaam AND wachtwoord = @wachtwoord";
                MySqlCommand   command             = new MySqlCommand(query, conn);
                MySqlParameter gebruikersnaamParam = new MySqlParameter("@gebruikersnaam", MySqlDbType.VarChar);
                MySqlParameter wachtwoordParam     = new MySqlParameter("@wachtwoord", MySqlDbType.VarChar);

                gebruikersnaamParam.Value = _gebruikersnaam;
                wachtwoordParam.Value     = sha512Wachtwoord;

                command.Parameters.Add(gebruikersnaamParam);
                command.Parameters.Add(wachtwoordParam);

                MySqlDataReader datalezer = command.ExecuteReader();

                // Haalt de data op uit de database en vult het model met data
                bool      isnull    = true;
                Gebruiker gebruiker = null;
                while (datalezer.Read())
                {
                    string gebruikersnaam = datalezer.GetString("gebruikersnaam");
                    string soortgebruiker = datalezer.GetString("soortgebruiker");
                    gebruiker = new Gebruiker()
                    {
                        Gebruikersnaam = gebruikersnaam, SoortGebruiker = soortgebruiker
                    };
                    isnull = false;

                    // Roept het hoofdmenu aan
                    HoofdmenuForm hoofdmenu = new HoofdmenuForm(gebruiker);
                    hoofdmenu.Show();
                }

                // Null checkt
                if (isnull == true)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (MySqlException e)
            {
                Console.WriteLine("Error in logincontroller - verifieergebruiker: " + e);
                return(false);
            }
            finally
            {
                conn.Close();
            }
        }
Exemple #2
0
        public void voegGebruikerToe(Gebruiker _gebruiker)
        {
            MySqlTransaction    trans = null;
            EncryptieController ecr   = new EncryptieController();

            _gebruiker.Wachtwoord = ecr.encrypt(_gebruiker.Wachtwoord);
            try
            {
                conn.Open();
                trans = conn.BeginTransaction();
                string         query               = "INSERT INTO gebruiker (gebruikersnaam, wachtwoord, soortgebruiker) VALUES (@gebruikersnaam, @wachtwoord, @soortgebruiker)";
                MySqlCommand   command             = new MySqlCommand(query, conn);
                MySqlParameter gebruikersnaamParam = new MySqlParameter("@gebruikersnaam", MySqlDbType.VarChar);
                MySqlParameter wachtwoordParam     = new MySqlParameter("@wachtwoord", MySqlDbType.VarChar);
                MySqlParameter soortgebruikerParam = new MySqlParameter("@soortgebruiker", MySqlDbType.VarChar);

                gebruikersnaamParam.Value = _gebruiker.Gebruikersnaam;
                wachtwoordParam.Value     = _gebruiker.Wachtwoord;
                soortgebruikerParam.Value = _gebruiker.SoortGebruiker;


                command.Parameters.Add(gebruikersnaamParam);
                command.Parameters.Add(wachtwoordParam);
                command.Parameters.Add(soortgebruikerParam);

                command.Prepare();
                command.ExecuteNonQuery();

                trans.Commit();

                // Voeg profiel toe
                if (_gebruiker.SoortGebruiker == "Docent" || _gebruiker.SoortGebruiker == "Admin")
                {
                    ProfielController profielcontroller = new ProfielController();
                    profielcontroller.voegProfielToe(_gebruiker.Gebruikersnaam);
                }
            }
            catch (MySqlException e)
            {
                if (trans != null)
                {
                    trans.Rollback();
                }
                Console.WriteLine("Error in gebruikercontroller - voeggebruikertoe: " + e);
            }
            finally
            {
                conn.Close();
            }
        }
Exemple #3
0
        public void veranderWachtwoordGebruiker(Gebruiker _gebruiker)
        {
            MySqlTransaction    trans = null;
            EncryptieController ecr   = new EncryptieController();

            _gebruiker.Wachtwoord = ecr.encrypt(_gebruiker.Wachtwoord);
            try
            {
                conn.Open();
                trans = conn.BeginTransaction();

                string         query               = "UPDATE gebruiker SET wachtwoord = @wachtwoord WHERE gebruikersnaam = @gebruikersnaam";
                MySqlCommand   command             = new MySqlCommand(query, conn);
                MySqlParameter gebruikersnaamParam = new MySqlParameter("gebruikersnaam", MySqlDbType.VarChar);
                MySqlParameter wachtwoordParam     = new MySqlParameter("wachtwoord", MySqlDbType.VarChar);
                gebruikersnaamParam.Value = _gebruiker.Gebruikersnaam;
                wachtwoordParam.Value     = _gebruiker.Wachtwoord;
                command.Parameters.Add(gebruikersnaamParam);
                command.Parameters.Add(wachtwoordParam);

                command.Prepare();
                command.ExecuteNonQuery();
                trans.Commit();
            }
            catch (MySqlException e)
            {
                if (trans != null)
                {
                    trans.Rollback();
                }
                Console.WriteLine("Error in gebruikercontroller - veranderwachtwoordgebruiker: " + e);
            }
            finally
            {
                conn.Close();
            }
        }