public void AddGenesisBlock(string type) { switch (type) { case "credentrails": BlockchainCredentials bcCredentials = new BlockchainCredentials(); Chain.Add(new Block(DateTime.Now, null, bcCredentials)); break; case "data": BlockchainData bcData = new BlockchainData(); Chain.Add(new Block(DateTime.Now, null, bcData)); break; case "reports": BlockchainReports bcReports = new BlockchainReports(); Chain.Add(new Block(DateTime.Now, null, bcReports)); break; case "ratings": BlockchainRatings bcRatings = new BlockchainRatings(); Chain.Add(new Block(DateTime.Now, null, bcRatings)); break; } }
public Block(DateTime timeStamp, string previousHash, BlockchainCredentials data) { Index = 0; TimeStamp = timeStamp.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffff"); PreviousHash = previousHash; DataCredentials = data; Hash = CalculateHash(); }
private void BtnRegister_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(tbUserName.Text) || string.IsNullOrEmpty(tbPassword.Password)) { MessageBox.Show("Login lub hasło nie mogą być puste!", "Ostrzeżenie", MessageBoxButton.OK, MessageBoxImage.Warning); tbUserName.BorderBrush = Brushes.Red; tbUserName.Background = Brushes.MistyRose; tbPassword.Clear(); tbPassword.BorderBrush = Brushes.Red; tbPassword.Background = Brushes.MistyRose; return; } bool userExist = false; foreach (var p in credentials.Chain) { if (p.DataCredentials.Login == tbUserName.Text) { userExist = true; break; } } if (userExist == false) { counter = 0; acceptedRequest = 0; acceptedAccount = false; MessagePack mp = new MessagePack(); BlockchainCredentials bc = new BlockchainCredentials(); bc.Login = tbUserName.Text; bc.Password = ComputeSha256Hash(tbPassword.Password); mp.SmObj = new Block(DateTime.Now, null, bc); mp.Text = "createNewUserRequest"; byte[] data = Blockchain.ObjectToByteArray(mp); sendingClient.Send(data, data.Length); MessageBox.Show("Prośba o dołączenie do systemu została wysłana do innych użytkowników. Zaczekaj, aż inni użytkownicy zaakceptują Twoją prośbę!", "Informacja", MessageBoxButton.OK, MessageBoxImage.Information); tbUserName.BorderBrush = Brushes.Gray; tbUserName.Background = Brushes.White; tbPassword.BorderBrush = Brushes.Gray; tbPassword.Background = Brushes.White; } else { MessageBox.Show("Użytkownik o podanym loginie istnieje już w systemie!", "Ostrzeżenie", MessageBoxButton.OK, MessageBoxImage.Warning); tbUserName.BorderBrush = Brushes.Red; tbUserName.Background = Brushes.MistyRose; tbPassword.Clear(); tbPassword.BorderBrush = Brushes.Red; tbPassword.Background = Brushes.MistyRose; return; } }
public Block CreateCredentialsGenesisBlock() { BlockchainCredentials bc = new BlockchainCredentials(); return(new Block(DateTime.Now, null, bc)); }
public void AddCredentialsGenesisBlock() //W PRZYSZŁOŚCI DO USUNIĘCIA, OBSŁUGA MOŻE BYĆ ZASTĄPIONA POWYŻEJ { BlockchainCredentials bc = new BlockchainCredentials(); Chain.Add(new Block(DateTime.Now, null, bc)); }
private void BtnRegister_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(tbUserName.Text) || string.IsNullOrEmpty(tbPassword.Password)) { MessageBox.Show("Uzupełnij wszystkie pola formularza logowania.", "Ostrzeżenie", MessageBoxButton.OK, MessageBoxImage.Warning); tbUserName.BorderBrush = Brushes.Red; tbUserName.Background = Brushes.MistyRose; tbPassword.Clear(); tbPassword.BorderBrush = Brushes.Red; tbPassword.Background = Brushes.MistyRose; return; } bool userExist = false; foreach (var p in credentials.Chain) { if (p.DataCredentials.Login == tbUserName.Text) { userExist = true; break; } } if (userExist == false) { counter = 0; acceptedRequest = 0; acceptedAccount = false; MessagePack mp = new MessagePack(); BlockchainCredentials bc = new BlockchainCredentials(); bc.Login = tbUserName.Text; bc.Password = ComputeSha256Hash(tbPassword.Password); MessageBoxResult boxResult = MessageBox.Show("Czy chcesz pełnić rolę producenta informacji?", "Wybór roli", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); if (boxResult == MessageBoxResult.Yes) { bc.UserType = true; } else if (boxResult == MessageBoxResult.No) { bc.UserType = false; } else { return; } mp.SmObj = new Block(DateTime.Now, null, bc); mp.Text = "createNewUserRequest"; byte[] data = Blockchain.ObjectToByteArray(mp); sendingClient.Send(data, data.Length); MessageBox.Show("Prośba o dołączenie do systemu została wysłana do innych użytkowników. Zaczekaj, aż inni użytkownicy zaakceptują Twoją prośbę!", "Informacja", MessageBoxButton.OK, MessageBoxImage.Information); tbUserName.BorderBrush = Brushes.Gray; tbUserName.Background = Brushes.White; tbPassword.BorderBrush = Brushes.Gray; tbPassword.Background = Brushes.White; } else { MessageBox.Show("Podany login jest już zajęty.", "Ostrzeżenie", MessageBoxButton.OK, MessageBoxImage.Warning); tbUserName.BorderBrush = Brushes.Red; tbUserName.Background = Brushes.MistyRose; tbPassword.Clear(); tbPassword.BorderBrush = Brushes.Red; tbPassword.Background = Brushes.MistyRose; return; } }