private void bValidate_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (tbNumber.Text == "" || tbYear.Text == "")
         {
             throw new Exception("Number or year are empty");
         }
         if (!RegexFunction.isNumber(tbNumber.Text))
         {
             throw new Exception("Number value isn't a number");
         }
         if (!RegexFunction.isNumber(tbYear.Text))
         {
             throw new Exception("Year value isn't a number");
         }
         if (Convert.ToInt16(tbYear.Text) < DateTime.Now.Year)
         {
             throw new Exception("Year value is anterior as the actual Year");
         }
         DateTime expiration = new DateTime(Int32.Parse(tbYear.Text), month, 1);
         number = StringCipher.Encrypt(tbNumber.Text, user.login);
         Card card = new Card(0, number, expiration, type, user.userID);
         addCard(ref card);
         DialogResult = true;
         this.Close();
     }
     catch (Exception ex)
     {
         lblErrorMsg.Content = ex.Message;
     }
 }
        /// <summary>
        /// Test if the login and the password correspond to a user in the database
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool ValiderFunction(ref User user)
        {
            try
            {
                if (user.login == "" || user.password == "")
                {
                    throw new Exception("Login or Password is empty");
                }
                if (!RegexFunction.isValidstring(user.login, 1, 40))
                {
                    throw new Exception("Login doesn't correspond to the standard");
                }
                if (!RegexFunction.isValidPassword(user.password))
                {
                    throw new Exception("Password doesn't correspond to the standard");
                }

                BDD  mybdd    = new BDD();
                User userTest = new User();
                if (mybdd.getUser(user.login, ref userTest) != 1)
                {
                    throw new Exception("Login doesn't exist in the database");
                }
                string hashedPassword = user.password;
                user = userTest;
                return(BCrypt.Net.BCrypt.Verify(hashedPassword, user.password));
            }
            catch
            {
                return(false);
            }
        }
        private void btRegister_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //test des différents champs
                if (!RegexFunction.isValidstring(tbLogin.Text, 1, 30))
                {
                    throw new Exception("Login invalid");
                }
                if (!RegexFunction.isValidPassword(passwordBox1.Password) && passwordBox1.Password == passwordBox2.Password)
                {
                    throw new Exception("Password invalid");
                }
                if (!RegexFunction.isValidstring(tbFirstName.Text, 1, 40))
                {
                    throw new Exception("FirstName invalid");
                }
                if (!RegexFunction.isValidstring(tbLastName.Text, 1, 40))
                {
                    throw new Exception("LastName invalid");
                }
                if (!RegexFunction.isValidEmail(tbEmail.Text))
                {
                    throw new Exception("Email invalid");
                }

                //verification du login
                BDD  mybdd = new BDD();
                User user  = new User();
                if (mybdd.getUser(tbLogin.Text, ref user) == 1)
                {
                    throw new Exception("Login already exist in the database");
                }
                string hashedPassword = BCrypt.Net.BCrypt.HashPassword(passwordBox1.Password);
                user = new User(0, tbFirstName.Text, tbLastName.Text, tbEmail.Text, hashedPassword, tbLogin.Text);
                mybdd.addUser(user);
                this.Close();
            }
            catch (Exception ex)
            {
                lblErrorMsg.Content = ex.Message;
            }
        }