Exemplo n.º 1
0
 private void BRegister_Click(object sender, EventArgs e)
 {
     if (TLogin.Text == "" || TPassword1.Text == "" || TPassword2.Text == "" || TServerIP.Text == "")
     {
         MessageBox.Show("Przynajmniej jedno z wymaganych pól jest nieuzupełnione!", "Błąd!");
     }
     else if (TPassword1.Text != TPassword2.Text)
     {
         MessageBox.Show("Podane hasła nie są identyczne!", "Błąd!");
     }
     else
     {
         Regex regex = new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$");
         Match match = regex.Match(TPassword1.Text);
         if (match.Success)
         {
             try
             {
                 Program.client = new SynchronousClient(TServerIP.Text);
                 var serverKey = Communique.KeyExchange();
                 if (serverKey != null)
                 {
                     var sessKey = Program.security.SetSessionKey(serverKey);
                     if (Communique.Register(TLogin.Text, TPassword1.Text, sessKey) == true)
                     {
                         MessageBox.Show("Rejestracja użytkownika " + TLogin.Text + " przebiegła pomyślnie!", "Sukces!");
                         this.DialogResult = DialogResult.No;
                         this.Close();
                     }
                     else
                     {
                         MessageBox.Show("Podany login jest już zajęty!", "Błąd!");
                         Program.client.Disconnect();
                     }
                 }
                 else
                 {
                     Program.client.Disconnect();
                     MessageBox.Show("Problem z połączeniem z serwerem!", "Błąd!");
                 }
             }
             catch (Exception)
             {
                 MessageBox.Show("Problem z połączeniem z serwerem lub adres jest niepoprawny!", "Błąd!");
             }
         }
         else
         {
             MessageBox.Show("Hasło nie spełnia kryteriów!", "Błąd!");
         }
     }
 }
Exemplo n.º 2
0
 private void BLogIn_Click(object sender, EventArgs e)
 {
     if (TLogin.Text == "" || TPassword.Text == "" || TServerIP.Text == "")
     {
         MessageBox.Show("Przynajmniej jedno z wymaganych pól jest nieuzupełnione!", "Błąd!");
     }
     else
     {
         try
         {
             Program.client = new SynchronousClient(TServerIP.Text);
             var serverKey = Communique.KeyExchange();
             if (serverKey != null)
             {
                 var sessKey = Program.security.SetSessionKey(serverKey);
                 if (Communique.LogIn(TLogin.Text, TPassword.Text, sessKey) == true)
                 {
                     Program.userLogin            = TLogin.Text;
                     Program.serverAddress        = TServerIP.Text;
                     this.DialogResult            = DialogResult.Yes;
                     Program.sessionKeyWithServer = sessKey;
                     this.Close();
                 }
                 else
                 {
                     MessageBox.Show("Podane dane logowania są niepoprawne lub użytkownik jest już zalogowany!", "Błąd!");
                 }
             }
             else
             {
                 Program.client.Disconnect();
                 MessageBox.Show("Problem z połączeniem z serwerem!", "Błąd!");
             }
         }
         catch (Exception)
         {
             MessageBox.Show("Problem z połączeniem z serwerem lub adres jest niepoprawny!", "Błąd!");
         }
     }
 }