Ejemplo n.º 1
0
        // Made by Jelle de Vries
        private void CheckCredentials()
        {
            ChapooLogic.Employee_Service service        = new ChapooLogic.Employee_Service();
            ChapooLogic.Function_Service functieService = new ChapooLogic.Function_Service();
            // check if input is is valid input
            if (string.IsNullOrEmpty(txt_User.Text) || string.IsNullOrEmpty(txt_Pass.Text) || !int.TryParse(txt_User.Text, out int id))
            {
                lbl_Error.Text = "Incorrect Username/Password";
            }
            //assign values to var
            string   password        = txt_Pass.Text;
            Employee huidigGebruiker = new Employee();

            huidigGebruiker.username = txt_User.Text;
            // get salt with username
            string       salt     = service.GetSalt(huidigGebruiker);
            HashwithSalt retrieve = new HashwithSalt();
            // generate hash with input password and the retrieved salt
            string hash = retrieve.GenerateHash(password, salt);

            // get credentials and check if they are valid
            /*            Employee employee = employee_service.GetCredentials(int.Parse(huidigGebruiker.username), hash);*/
            huidigGebruiker.validlogin = 1;

            // show welcome box if login is valid
            if (huidigGebruiker.validlogin == 1)
            {
                int function = functieService.GetFunctie(huidigGebruiker);
                MessageBox.Show($"Welkom {huidigGebruiker.username.ToUpper()}\n\nU bent ingelogd met functie: {(Employee.FunctieNaam)function}");

                this.Hide();
                //  open correct form according to function
                if (function == 1)
                {
                    Boolean       keuken       = false;
                    BarKeukenForm barOverzicht = new BarKeukenForm(keuken);
                    barOverzicht.Show();
                }
                else if (function == 2)
                {
                    AdminForm adminform = new AdminForm();
                    adminform.Show();
                }
                else if (function == 3)
                {
                    Boolean       keuken          = true;
                    BarKeukenForm keukenOverzicht = new BarKeukenForm(keuken);
                    keukenOverzicht.Show();
                }
                else if (function == 4)
                {
                    BedieningForm bedieningForm = new BedieningForm();
                    bedieningForm.Show();
                }
                else
                {
                    MessageBox.Show("Geen functie gevonden.");
                }
            }
        }
Ejemplo n.º 2
0
        private void btn_check_Click(object sender, EventArgs e)
        {
            // check is entered string is valid
            if (!string.IsNullOrWhiteSpace(txt_answer.Text))
            {
                ChapooLogic.Employee_Service service = new Employee_Service();
                Employee employee = new Employee();

                employee.username = txt_User.Text;
                string answer;

                //get answer
                answer = service.forgotpass(employee);

                // check if answer matches
                if (txt_answer.Text.ToLower() == answer.ToLower())
                {
                    // if passwords match
                    if (txt_newpass == txt_repeatpass)
                    {
                        //call hashing function
                        HashwithSalt hash = new HashwithSalt();
                        // create salt and create hash
                        string salt   = hash.CreateSalt(64);
                        string hashed = hash.GenerateHash(txt_newpass.Text, salt);
                        //grab and parse username
                        int username = int.Parse(txt_User.Text);

                        // change password
                        service.Alterpass(username, hashed, salt);
                        // show success
                        MessageBox.Show("Je wachtwoord is succesvol veranderd");


                        // open login form again
                        LoginForm loginForm = new LoginForm();
                        loginForm.Show();
                        this.Close();
                    }
                }
                else //display fail if answer is wrong
                {
                    MessageBox.Show("Foutief antwoord op de vraag");
                }
            }
        }