private void signInBtn_Click(object sender, RoutedEventArgs e) { statusLabel.Content = ""; string login = loginTB.Text.Trim(); if (login.Length == 0 || passTB.Password.Length == 0) { statusLabel.Content = "Введите логин и пароль"; return; } string expectedDigest = GetAccountDigest(login); if (expectedDigest.Length == 0) { statusLabel.Content = "Пользователь не найден"; return; } string saltyDigest = Utils.ByteArrayToHexString(Cryptography. GetSha1(passTB.Password + Cryptography.SALT)); if (!saltyDigest.Equals(expectedDigest)) { statusLabel.Content = "Неправильный пароль"; return; } Account account = Account.Deserialize(login); Start(account); }
private void signUpBtn_Click(object sender, RoutedEventArgs e) { statusLabel.Content = ""; string login = loginTB.Text.Trim(); if (login.Length == 0 || passTB.Password.Length == 0) { statusLabel.Content = "Введите логин и пароль"; return; } if (GetAccountDigest(login).Length > 0) { statusLabel.Content = "Пользователь с таким логином уже существует"; return; } string saltyDigest = Utils.ByteArrayToHexString(Cryptography. GetSha1(passTB.Password + Cryptography.SALT)); Account user = new Account(login, saltyDigest); user.Serialize(); using (StreamWriter fs = new StreamWriter(Account.GetAccountsListPath(), true)) { fs.WriteLine(user.login); fs.WriteLine(user.digest); } Start(user); }
internal CryptoKey(string publicKey, string privateKey, string name, string ownerAddress, Purpose purpose) { this.Name = name; this.Id = Utils.ByteArrayToHexString(Cryptography.GetSha1(publicKey)); this.OwnerAddress = ownerAddress; this.PublicKey = publicKey; this.PrivateKey = privateKey; this.PublicOnly = PrivateKey == null; this.KeyPurpose = purpose; this.DateTime = DateTime.Now; }