コード例 #1
0
        private async void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            // make sure user can't press button multiple times
            LoginButton.IsEnabled = false;

            try
            {
                // load RSA key
                string containerName = RSAKeyTextBox.Text;
                await Task.Run(() => { AsymmetricEncryption.SelectKeyPair(containerName, 4096); });

                // log in and wait for at least 1.5s, whichever finishes last
                List <Task> tasks = new List <Task>();

                tasks.Add(Client.Login(EmailTextBox.Text, PasswordPasswordBox.Password));

                tasks.Add(Task.Delay(1_500));

                await Task.WhenAll(tasks);

                //move to chat window
                ChatWindow chat = new ChatWindow();
                chat.Show();
                this.Close();
            }
            catch (ClientException exception)
            {
                // show error message
                ErrorLabel.Visibility = Visibility.Visible;
                ErrorLabel.Content    = exception.Message;
            }

            // re-enable user input
            LoginButton.IsEnabled = true;
        }
コード例 #2
0
        public void SelectKeyPair_Should_Change_Public_Key()
        {
            RSAParameters beforeParams = AsymmetricEncryption.PublicKey;

            AsymmetricEncryption.SelectKeyPair("otherPair", 512);

            RSAParameters afterParams = AsymmetricEncryption.PublicKey;

            Assert.That(beforeParams, Is.Not.EqualTo(afterParams));
        }
コード例 #3
0
        private async void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            // make sure user can't press button multiple times
            RegisterButton.IsEnabled = false;

            // make error label empty
            ErrorLabel.Content = "";

            // check email
            if (!emailRegex.IsMatch(EmailTextBox.Text.Trim()))
            {
                ErrorLabel.Content       = "Invalid email.";
                RegisterButton.IsEnabled = true;
                return;
            }

            // check password
            if (!passwordRegex.IsMatch(PasswordTextBox.Password.Trim()))
            {
                ErrorLabel.Content       = "Invalid password. Password should contain at least 1 upper case letter and 1 number.";
                RegisterButton.IsEnabled = true;
                return;
            }

            // check if passwords match
            if (!PasswordTextBox.Password.Equals(PasswordConfirmationTextBox.Password))
            {
                ErrorLabel.Content       = "Password and Password Confirmation are different.";
                RegisterButton.IsEnabled = true;
            }

            try
            {
                // load given RSA container
                string containerName = RSAKeyTextBox.Text;
                await Task.Run(() => { AsymmetricEncryption.SelectKeyPair(containerName, 4096); });

                List <Task> tasks = new List <Task>();

                // try to register
                tasks.Add(Client.Register(EmailTextBox.Text, PasswordTextBox.Password.Trim(), FirstNameTextBox.Text.Trim(), LastNameTextBox.Text.Trim(), AsymmetricEncryption.PublicKeyAsXml()));

                // wait at least 3 seconds
                tasks.Add(Task.Delay(3_000));

                // wait for 3 second timer and registration to complete, whichever finishes last
                await Task.WhenAll(tasks);

                // move to login window
                LoginWindow login = new LoginWindow(EmailTextBox.Text.Trim(), PasswordTextBox.Password, RSAKeyTextBox.Text);
                login.Show();
                this.Close();
            }
            catch (ClientException exception)
            {
                // show error message
                ErrorLabel.Visibility = Visibility.Visible;
                ErrorLabel.Content    = exception.Message;
            }

            // re-enable user input
            RegisterButton.IsEnabled = true;
        }
コード例 #4
0
 /// <summary>
 /// Load private key from container
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="routedEventArgs"></param>
 private void LoadPrivateKey(object sender, RoutedEventArgs routedEventArgs)
 {
     AsymmetricEncryption.SelectKeyPair(PrivateRSAContainerName.Text.Trim(), 4096);
 }