Example #1
0
        private void pwdGenButton_Click(object sender, EventArgs e)
        {
            PwdParamsView pwdParamsView = new PwdParamsView();

            pwdParamsView.ShowDialog();
            PwdGenerator pGen = new PwdGenerator(pwdParamsView, id);

            MessageBox.Show("Votre mot de passe pour " + pwdParamsView.softName + " est :\n" + pGen.pwd, "Succès", MessageBoxButtons.OK);
            MessageBox.Show("Votre mot de passe a été enregistré avec succès!", "Sauvegarde", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #2
0
        private void create_pwd(PwdParamsView param, int idUser)
        {
            DicoGen dico  = new DicoGen();
            Random  rand  = new Random();
            int     typec = 0; // choose char type (nb -> 0, Maj -> 1, min -> 2, spec -> 3)
            int     i     = -1;

            pwd = "";

            while (i++ != param.pwdLenght - 1)
            {
                typec = rand.Next(0, 4); //!\\ valeur min inclusive, valeur maxi exclusive
                if (!param.nb && typec == 0 || !param.Maj && typec == 1 || !param.min && typec == 2)
                {
                    typec++;
                }
                if (!param.spec && typec == 3)
                {
                    typec = 0;
                }

                switch (typec)
                {
                case 0:
                    tmp[i] = dico.nb[rand.Next(0, dico.nb.Length)];
                    break;

                case 1:
                    tmp[i] = dico.Maj[rand.Next(0, dico.Maj.Length)];
                    break;

                case 2:
                    tmp[i] = dico.min[rand.Next(0, dico.min.Length)];
                    break;

                case 3:
                    tmp[i] = dico.spec[rand.Next(0, dico.spec.Length)];
                    break;
                }

                /* if (typec == 0)
                 *  tmp[i] = dico.nb[rand.Next(0, dico.nb.Length)];
                 * else if (typec == 1)
                 *  tmp[i] = dico.Maj[rand.Next(0, dico.Maj.Length)];
                 * else if (typec == 2)
                 *  tmp[i] = dico.min[rand.Next(0, dico.min.Length)];
                 * else if (typec == 0)
                 *  tmp[i] = dico.spec[rand.Next(0, dico.spec.Length)];
                 */
                pwd += tmp[i];
            }
            save_datas(param, idUser);
        }
Example #3
0
 private void save_datas(PwdParamsView param, int idUser)
 {
     using (jPwdGenEntities pwdDb = new jPwdGenEntities())
     {
         PwdUser pwdU = new PwdUser()
         {
             ID_USER = idUser,
             LB_PWD  = pwd,
             LB_SOFT = param.softName
         };
         pwdDb.PwdUser.Add(pwdU);
         pwdDb.SaveChanges();
     }
 }
Example #4
0
 public PwdGenerator(PwdParamsView param, int idUser)
 {
     tmp = new char[param.pwdLenght];
     create_pwd(param, idUser);
 }