コード例 #1
0
        private void Register()
        {
            CscUserData userData = new CscUserData()
            {
                Email    = RegisterEmailTextBox.Text,
                Password = CscSHA512Generator.get_SHA512_hash_as_string(RegisterPasswordTextBox.Password)
            };
            var bytesToSend = protocol.CreateRegistrationMessageEncrypted(userData, client.DH.Key);

            client.SendBytes(bytesToSend);

            var response         = client.ReceiveBytes();
            var messageEncrypted = response.Skip(3).ToArray();
            var msg = client.AES.DecryptStringFromBytes(messageEncrypted);

            if (response[0] == 12)
            {
                MessageBox.Show(msg);
            }
            if (response[0] == 13)
            {
                MessageBox.Show(msg);
                return;
            }
            else
            {
                //MessageBox.Show(Encoding.Unicode.GetString(response));
            }
        }
コード例 #2
0
        public bool Authenticate(CscUserData receivedData, CscUserData userFromDatabase)
        {
            if (receivedData.Email != userFromDatabase.Email)
            {
                return(false);
            }

            if (receivedData.Password != userFromDatabase.Password)
            {
                return(false);
            }

            return(true);
        }
コード例 #3
0
        private void EmailButton_Click(object sender, RoutedEventArgs e)
        {
            if (!EmailValidator.IsValid(EmailTextBox.Text))
            {
                MessageBox.Show("Adres email niepoprawny!");
                return;
            }

            var         NewEmail = EmailTextBox.Text;
            CscUserData userData = new CscUserData()
            {
                Email    = NewEmail,
                Password = CscSHA512Generator.get_SHA512_hash_as_string(CscSHA512Generator.get_SHA512_hash_as_string(ChangeEmailPasswordBox.Password) + client.salt)
            };

            client.SendChangeEmailRequestEncrypted(userData);

            var WaitForMessageTask = Task.Run(() => WaitForEmailMessage(NewEmail));
        }
コード例 #4
0
        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            if (!EmailValidator.IsValid(EmailTextBox.Text))
            {
                MessageBox.Show("Adres email niepoprawny!");
                return;
            }

            try
            {
                CscUserData userData = new CscUserData()
                {
                    Email    = EmailTextBox.Text,
                    Password = CscSHA512Generator.get_SHA512_hash_as_string(CscSHA512Generator.get_SHA512_hash_as_string(PasswordTextBox.Password) + client.salt)
                };
                var bytesToSend = protocol.CreateLoginMessageEncrypted(userData, client.DH.Key);
                client.SendBytes(bytesToSend);
                //MessageBox.Show("wysyłam hasło z solą " + userData.Password);
                client.UserProfile.Email = EmailTextBox.Text;//n

                var response = client.ReceiveBytes();
                //var length = BitConverter.ToInt16(response.Skip(1).Take(2).ToArray(), 0);
                var messageEncrypted = response.Skip(3).ToArray();
                var message          = client.AES.DecryptStringFromBytes(messageEncrypted);
                if (response[0] == 12)
                {
                    //MessageBox.Show(Encoding.Unicode.GetString(message, 0, length));//witaj na serwerze

                    //Create main window
                    client.initialized = true;
                    ClientMainWindow mainWindow = new ClientMainWindow(client, false);
                    mainWindow.Show();
                    this.Close();
                }
                if (response[0] == 13)
                {
                    //MessageBox.Show(Encoding.Unicode.GetString(message, 0, length));
                    MessageBox.Show(message);
                    return;
                }
                else
                {
                    //MessageBox.Show(Encoding.Unicode.GetString(response));
                }
            }
            catch (SocketException ex)
            {
                MessageBox.Show("Nastąpiło rozłączenie z serwerem: " + ex.Message);
                client.Disconnect();
                ConnectionWindow window = new ConnectionWindow();
                window.Show();
                Close();
            }
            catch (IOException)
            {
                MessageBox.Show("Nie otrzymano odpowiedzi od serwera");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Wystąpił nieznany błąd: " + ex.Message);
            }
        }