Skip to content

Commit

Permalink
Set raw hashes for file base
Browse files Browse the repository at this point in the history
  • Loading branch information
CryptKat committed Jul 12, 2022
1 parent d05da0c commit 5d894d5
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 21 deletions.
17 changes: 17 additions & 0 deletions PasswordChanger1C/AccessFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,23 @@ public static void UpdatePassword_IB(ref Dictionary<string, object> Row, in stri
Row["DATA_BINARY"] = NewBytes;
}

public static void UpdateRawHashes_IB(ref Dictionary<string, object> Row, in string passHash, in string passHash2)
{
var OldDataBinary = (byte[])Row["DATA_BINARY"];
string OldData = Row["DATA"].ToString();

Row["OLD_DATA_BINARY"] = OldDataBinary;
Row["OLD_DATA"] = OldData;

var NewHashes = Tuple.Create(passHash, passHash2);
var OldHashes = Tuple.Create(Row["UserPassHash"].ToString(), Row["UserPassHash2"].ToString());
string NewData = CommonModule.ReplaceHashes(OldData, OldHashes, NewHashes);
var NewBytes = CommonModule.EncodePasswordStructure(NewData, Convert.ToInt32(Row["DATA_KEYSIZE"]), (byte[])Row["DATA_KEY"]);

Row["DATA"] = NewData;
Row["DATA_BINARY"] = NewBytes;
}

public static void ParseUsersData_IB(ref List<Dictionary<string, object>> Records)
{
if (Records is null)
Expand Down
57 changes: 40 additions & 17 deletions PasswordChanger1C/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 66 additions & 4 deletions PasswordChanger1C/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ private void Fill_itemUserList_IB()
itemUserList.SubItems.Add(Row["NAME"].ToString());
itemUserList.SubItems.Add(Row["DESCR"].ToString());
itemUserList.SubItems.Add(Row["UserPassHash"].ToString());
itemUserList.SubItems.Add(Row["UserPassHash2"].ToString());
itemUserList.SubItems.Add(CommonModule.Format_AdmRole((bool)Row["ADMROLE"]));
ListViewUsers.Items.Add(itemUserList);
}
Expand Down Expand Up @@ -508,11 +509,11 @@ private void SetRawHashesSQL_Click(object sender, EventArgs e)

private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
foreach (var item in SQLUserList.SelectedItems)
var listView = TabControl1.SelectedIndex == 1 ? SQLUserList : ListViewUsers;
StringBuilder sb = new();
foreach (var item in listView.SelectedItems)
{
ListViewItem l = item as ListViewItem;
if (l != null)
if (item is ListViewItem l)
foreach (ListViewItem.ListViewSubItem sub in l.SubItems)
sb.Append(sub.Text + "\t");
sb.AppendLine();
Expand All @@ -527,5 +528,66 @@ private void SQLUserList_MouseClick(object sender, MouseEventArgs e)
ContextMenu.Show(SQLUserList, e.Location);
}
}

private void SetRawHashes_Click(object sender, EventArgs e)
{
if (ListViewUsers.SelectedItems.Count == 0)
{
MessageBox.Show("Не выделены строки с пользователями для сброса пароля!",
"Не выделены строки с пользователями", MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}

var Rez = MessageBox.Show("Внесение изменений в файл информационной базы может привести к непредсказуемым последствиям, вплоть до полного разрушения базы! " + Environment.NewLine +
"Продолжая операцию Вы осознаете это и понимаете, что восстановление будет возможно только из резервной копии." + Environment.NewLine +
"Установить новый пароль выбранным пользователям?",
"ВНИМАНИЕ!", MessageBoxButtons.YesNo);
if (Rez != DialogResult.Yes)
{
return;
}

using var form = new RawHashesPrompt();
if (form.ShowDialog() != DialogResult.OK)
return;

List<string> Selected_ID = new();
foreach (ListViewItem item in ListViewUsers.SelectedItems) Selected_ID.Add(item.Text);

var SelectedRows = TableParams.Records.FindAll(Row => Selected_ID.Contains(Row["UserGuidStr"].ToString()));
var UserNames = string.Join(", ", SelectedRows.Select(Row => Row["NAME"].ToString()));

try
{
foreach (var Row in SelectedRows)
{
var Current_Row = Row;
AccessFunctions.UpdateRawHashes_IB(ref Current_Row, form.PasswordHash.Text.Trim(), form.PasswordHash2.Text.Trim());
AccessFunctions.WritePasswordIntoInfoBaseIB(FileIB.Text, TableParams, Current_Row);
}
}
catch (Exception ex)
{
MessageBox.Show("Ошибка при попытке записи данных в файл информационной базы:" + Environment.NewLine +
ex.Message,
"Ошибка работы с файлом", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}

MessageBox.Show("Успешно установлен пароль для пользователей:" + UserNames,
"Операция успешно выполнена", MessageBoxButtons.OK,
MessageBoxIcon.Information);
GetUsers();
}

private void ListViewUsers_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ContextMenu.Show(ListViewUsers, e.Location);
}
}
}
}
1 change: 1 addition & 0 deletions PasswordChanger1C/RawHashesPrompt.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d894d5

Please sign in to comment.