Exemplo n.º 1
0
        private void btnsubmit_Click(object sender, EventArgs e)
        {
            string username = txtusername.Text;
            string email    = txtemail.Text;
            string password = SHA.petitsha(txtpass.Text);

            User.RoleType role = User.RoleType.EMPLOYE;
            if (cbrole.Text == "Employe")
            {
                role = User.RoleType.EMPLOYE;
            }
            else if (cbrole.Text == "Admin")
            {
                role = User.RoleType.ADMIN;
            }

            string sql = $"insert into admin (username,email ,pass, Role) Values ('{username}', '{email}','{password}', {User.roleTypeToInt(role)})";


            if (DataBaseUtil.executeNonQuery(sql) > 0)
            {
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("User " + username + " exists already");
            }
        }
Exemplo n.º 2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtusername.Text == "" || txtpassword.Text == "")
            {
                MessageBox.Show("Remplissez tous les champs");
                return;
            }
            try
            {
                string username = txtusername.Text;
                string pass     = txtpassword.Text;
                pass = SHA.petitsha(pass);

                if (User.checkUserLocked(username))
                {
                    MessageBox.Show("Votre compte a été verouillé suite à 5 tentatives échouées");
                    this.DialogResult = DialogResult.Cancel;
                    return;
                }

                string          sql = $"Select id, username, pass, Role from admin where username='******'";
                MySqlDataReader rdr = DataBaseUtil.executeSelect(sql);
                if (rdr.Read())
                {
                    labelError.Visible = false;
                    int    id       = int.Parse(rdr[0].ToString());
                    string password = rdr[2].ToString();
                    bool   etat     = password.Equals(pass.ToLower());
                    role         = int.Parse(rdr[3].ToString());
                    nomoperateur = rdr[1].ToString();
                    if (etat)
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        int nbr = -1;
                        if (!dictUserConnexion.TryGetValue(username, out nbr))
                        {
                            dictUserConnexion.Add(username, 0);
                        }
                        dictUserConnexion[username]++;
                        nbr = dictUserConnexion[username];


                        if (dictUserConnexion[username] == 5)
                        {
                            User.lockUnlockUser(username, true);
                        }

                        labelError.Visible = true;
                    }
                    rdr.Close();
                    AjouterJournalConnexion(id, DateTime.Now, etat);
                }
                else
                {
                    labelError.Visible = true;
                }
            }
            catch
            {
            }

            ///this.StrLevel = "Administrateur";
        }