public void TestRandomSaltInEncryption()
        {
            CryptoPassword crypto = new CryptoPassword();

            string password      = "******";
            string firstEncrypt  = crypto.Hash(password);
            string secondEncrypt = crypto.Hash(password);

            Assert.AreNotEqual(firstEncrypt, secondEncrypt);
        }
        public void TestCryptPassword()
        {
            CryptoPassword crypto = new CryptoPassword();

            string clearPassword     = "******";
            string encryptedPassword = crypto.Hash(clearPassword);

            Assert.AreNotEqual(clearPassword, encryptedPassword);
        }
        public void TestPasswordVerifyWithGoodPassword()
        {
            CryptoPassword crypto = new CryptoPassword();

            string clearPassword     = "******";
            string encryptedPassword = crypto.Hash(clearPassword);

            bool verify = crypto.Verify(clearPassword, encryptedPassword);

            Assert.AreEqual(true, verify);
        }
        public void TestPasswordVerifyWithWrongPassword()
        {
            CryptoPassword crypto = new CryptoPassword();

            string actualPassword    = "******";
            string wrongPassword     = "******";
            string encryptedPassword = crypto.Hash(actualPassword);

            bool verify = crypto.Verify(wrongPassword, encryptedPassword);

            Assert.AreEqual(false, verify);
        }
        /// <summary>
        /// Register new users in the database, also check if the username is already used.
        /// </summary>
        /// <param name="reg">Contains userEmail, username and a password</param>
        /// <returns>True: Everything OK</returns>
        ///
        public bool RegisterInDb(Register reg)
        {
            DbConnection   connection     = new DbConnection();
            CryptoPassword c              = new CryptoPassword();
            string         hashedPassword = c.Hash(password);
            CheckData      registerCheck  = new CheckData();

            try
            {
                if (!registerCheck.CheckRegisterField(reg.userEmail, reg.password, reg.passwordCheck))
                {
                    return(false);
                }

                if (!registerCheck.VerifRegister(reg.userEmail, reg.password))
                {
                    return(false);
                }
                if (connection.CheckIfUserEmailExistInDb(userEmail))
                {
                    return(false);
                }

                if (!connection.InsertDataInDb(username, userEmail, hashedPassword))
                {
                    return(false);
                }
            }
            catch (InvalidEmailAddressException e)
            {
                MessageBox.Show(e.Message);
                return(false);
            }
            catch (EmptyFieldException e)
            {
                MessageBox.Show(e.Message);
                return(false);
            }
            catch (EmailTooShortException e)
            {
                MessageBox.Show(e.Message);
                return(false);
            }
            catch (PasswordTooShortException e)
            {
                MessageBox.Show(e.Message);
                return(false);
            }
            catch (UserEmailAlreadyExistException e)
            {
                MessageBox.Show(e.Message);
                return(false);
            }
            catch (MySqlException e)
            {
                MessageBox.Show("Un erreur est survenu lors de la connection avec la base de donnée");
                return(false);
            }

            return(true);
        }