public void Register(string username, string password) { string hashedPass = HashUtilities.HashPassword(password); byte[] key = HashUtilities.HashKey(password); string encryptedData = CryptographicUtilities.Encrypt(string.Empty, key); RegistryData.CreateUser(username, hashedPass, encryptedData); }
public static void Compose(BindingSource userData, string username, byte[] key) { StringBuilder builder = new StringBuilder(); foreach (var info in userData) { var hostInfo = (UserDataInfo)info; builder.AppendFormat("{0}{4}{1}{4}{2}{4}{3}{5}", hostInfo.HostName, hostInfo.Email, hostInfo.Username, hostInfo.Password, Constants.InfoSplitChar, Constants.HostsSplitChar); } string encrypedData = CryptographicUtilities.Encrypt(builder.ToString(), key); RegistryData.SetUserData(username, encrypedData); }
public static void SetRestoredData(string[] data) { for (int i = 1; i < data.Length; i++) { data[i] = CryptographicUtilities.Decrypt(data[i], Constants.backUpKey); } string username = data[1]; string logInfo = data[2]; string userData = data[3]; registry.OpenSubKey(Constants.UsersLoginSubKeyPath, true).SetValue(username, logInfo); registry.Close(); registry.OpenSubKey(Constants.UsersDataSubKeyPath, true).SetValue(username, userData); registry.Close(); }
private void changeButton_Click(object sender, EventArgs e) { this.oldPassLabel.Visible = false; this.newPassLabel.Visible = false; string currentPassword = this.oldPasswordTextBox.Text; string currentPasswordHash = HashUtilities.HashPassword(currentPassword); string hashedPassword = RegistryData.GetUserPassword(this.User.Username); if (currentPasswordHash == hashedPassword) { try { ValidateNewPassword(this.newPassTextBox.Text, this.confirmNewPassTextBox.Text); string oldEncryptedData = RegistryData.GetUserData(this.User.Username); string oldDecryptedData = CryptographicUtilities.Decrypt(oldEncryptedData, this.User.Key); string newPassword = HashUtilities.HashPassword(this.newPassTextBox.Text); byte[] newKey = HashUtilities.HashKey(this.newPassTextBox.Text); string newData = CryptographicUtilities.Encrypt(oldDecryptedData, newKey); RegistryData.SetNewPassword(this.User.Username, newPassword); RegistryData.SetUserData(this.User.Username, newData); this.User.SetNewKey(newKey); MetroMessageBox.Show(this.MainForm, string.Empty, GlobalMessages.PasswordChanged , MessageBoxButtons.OK, MessageBoxIcon.Information, 80); this.Swipe(false); } catch (InvalidPasswordLenghtException ipe) { this.newPassLabel.Text = ipe.Message; this.newPassLabel.Visible = true; } catch (PasswordMismatchException pme) { this.newPassLabel.Text = pme.Message; this.newPassLabel.Visible = true; } } else { this.oldPassLabel.Text = GlobalMessages.InvalidPassword; this.oldPassLabel.Visible = true; } }
public static string[] GetDataForBackup(string username) { string logInfo = registry.OpenSubKey(Constants.UsersLoginSubKeyPath).GetValue(username).ToString(); string userData = registry.OpenSubKey(Constants.UsersDataSubKeyPath).GetValue(username).ToString(); string[] dataForBackup = new string[4]; dataForBackup[0] = Constants.BackupMark; dataForBackup[1] = username; dataForBackup[2] = logInfo; dataForBackup[3] = userData; for (int i = 0; i < dataForBackup.Length; i++) { dataForBackup[i] = CryptographicUtilities.Encrypt(dataForBackup[i], Constants.backUpKey); } return(dataForBackup); }
public static BindingSource Parse(string username, byte[] key) { BindingSource parsedData = new BindingSource(); string encryptedData = RegistryData.GetUserData(username); string decrypedData = CryptographicUtilities.Decrypt(encryptedData, key); var splitedByHost = decrypedData.Split(new[] { Constants.HostsSplitChar } , StringSplitOptions.RemoveEmptyEntries); foreach (var info in splitedByHost) { string[] splitedInfo = info.Split(Constants.InfoSplitChar); UserDataInfo dataInfo = new UserDataInfo( splitedInfo[0], splitedInfo[1], splitedInfo[2], splitedInfo[3]); parsedData.Add(dataInfo); } return(parsedData); }