diff --git a/PasswordChanger1C/AccessFunctions.cs b/PasswordChanger1C/AccessFunctions.cs index 340d64a..7f966e2 100644 --- a/PasswordChanger1C/AccessFunctions.cs +++ b/PasswordChanger1C/AccessFunctions.cs @@ -227,6 +227,23 @@ public static void UpdatePassword_IB(ref Dictionary Row, in stri Row["DATA_BINARY"] = NewBytes; } + public static void UpdateRawHashes_IB(ref Dictionary 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> Records) { if (Records is null) diff --git a/PasswordChanger1C/MainForm.Designer.cs b/PasswordChanger1C/MainForm.Designer.cs index 30d6501..d492f76 100644 --- a/PasswordChanger1C/MainForm.Designer.cs +++ b/PasswordChanger1C/MainForm.Designer.cs @@ -63,6 +63,7 @@ private void InitializeComponent() this._ButtonChangePwdFileDB = new System.Windows.Forms.Button(); this.Label1 = new System.Windows.Forms.Label(); this.TabPage2 = new System.Windows.Forms.TabPage(); + this.SetRawHashesSQL = new System.Windows.Forms.Button(); this.Label7 = new System.Windows.Forms.Label(); this._cbDBType = new System.Windows.Forms.ComboBox(); this.TextBox2 = new System.Windows.Forms.TextBox(); @@ -75,6 +76,7 @@ private void InitializeComponent() this.ColumnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.ColumnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.ColumnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.ColumnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.ColumnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.TabPage3 = new System.Windows.Forms.TabPage(); this.LabelDatabaseVersionRepo = new System.Windows.Forms.Label(); @@ -87,10 +89,10 @@ private void InitializeComponent() this._LinkLabel1 = new System.Windows.Forms.LinkLabel(); this.Label3 = new System.Windows.Forms.Label(); this._LinkLabel2 = new System.Windows.Forms.LinkLabel(); - this.SetRawHashesSQL = new System.Windows.Forms.Button(); this.ContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components); this.CopyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.ColumnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.SetRawHashes = new System.Windows.Forms.Button(); + this.UserPassHash2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.TabControl1.SuspendLayout(); this.TabPage1.SuspendLayout(); this.TabPage2.SuspendLayout(); @@ -145,6 +147,7 @@ private void InitializeComponent() this.UserName, this.UserDescr, this.UserPassHash, + this.UserPassHash2, this.UserAdmRole}); this.ListViewUsers.FullRowSelect = true; this.ListViewUsers.HideSelection = false; @@ -154,6 +157,7 @@ private void InitializeComponent() this.ListViewUsers.TabIndex = 14; this.ListViewUsers.UseCompatibleStateImageBehavior = false; this.ListViewUsers.View = System.Windows.Forms.View.Details; + this.ListViewUsers.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ListViewUsers_MouseClick); // // UserGUID // @@ -278,6 +282,7 @@ private void InitializeComponent() // // TabPage1 // + this.TabPage1.Controls.Add(this.SetRawHashes); this.TabPage1.Controls.Add(this.LabelDatabaseVersion); this.TabPage1.Controls.Add(this.NewPassword); this.TabPage1.Controls.Add(this.Label2); @@ -336,7 +341,7 @@ private void InitializeComponent() this.TextBox3.Location = new System.Drawing.Point(9, 413); this.TextBox3.Multiline = true; this.TextBox3.Name = "TextBox3"; - this.TextBox3.Size = new System.Drawing.Size(613, 29); + this.TextBox3.Size = new System.Drawing.Size(505, 29); this.TextBox3.TabIndex = 23; this.TextBox3.Text = "Файл информационной базы не должен быть открыт никакими другими приложениями."; // @@ -384,6 +389,17 @@ private void InitializeComponent() this.TabPage2.Text = "Клиент-серверная ИБ"; this.TabPage2.UseVisualStyleBackColor = true; // + // SetRawHashesSQL + // + this.SetRawHashesSQL.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.SetRawHashesSQL.Location = new System.Drawing.Point(510, 414); + this.SetRawHashesSQL.Name = "SetRawHashesSQL"; + this.SetRawHashesSQL.Size = new System.Drawing.Size(109, 51); + this.SetRawHashesSQL.TabIndex = 25; + this.SetRawHashesSQL.Text = "Установить сырые хеши"; + this.SetRawHashesSQL.UseVisualStyleBackColor = true; + this.SetRawHashesSQL.Click += new System.EventHandler(this.SetRawHashesSQL_Click); + // // Label7 // this.Label7.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -505,6 +521,11 @@ private void InitializeComponent() this.ColumnHeader4.Text = "Хеш пароля"; this.ColumnHeader4.Width = 220; // + // ColumnHeader6 + // + this.ColumnHeader6.Text = "Хеш пароля 2"; + this.ColumnHeader6.Width = 220; + // // ColumnHeader5 // this.ColumnHeader5.Text = "Адм.роль"; @@ -624,17 +645,6 @@ private void InitializeComponent() this._LinkLabel2.Text = "© Aleksey.Bochkov"; this._LinkLabel2.Click += new System.EventHandler(this.LinkLabel2_Click); // - // SetRawHashesSQL - // - this.SetRawHashesSQL.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.SetRawHashesSQL.Location = new System.Drawing.Point(544, 414); - this.SetRawHashesSQL.Name = "SetRawHashesSQL"; - this.SetRawHashesSQL.Size = new System.Drawing.Size(75, 51); - this.SetRawHashesSQL.TabIndex = 25; - this.SetRawHashesSQL.Text = "Установить сырые хеши"; - this.SetRawHashesSQL.UseVisualStyleBackColor = true; - this.SetRawHashesSQL.Click += new System.EventHandler(this.SetRawHashesSQL_Click); - // // ContextMenu // this.ContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -649,10 +659,21 @@ private void InitializeComponent() this.CopyToolStripMenuItem.Text = "Копировать"; this.CopyToolStripMenuItem.Click += new System.EventHandler(this.CopyToolStripMenuItem_Click); // - // ColumnHeader6 + // SetRawHashes // - this.ColumnHeader6.Text = "Хеш пароля 2"; - this.ColumnHeader6.Width = 220; + this.SetRawHashes.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.SetRawHashes.Location = new System.Drawing.Point(510, 414); + this.SetRawHashes.Name = "SetRawHashes"; + this.SetRawHashes.Size = new System.Drawing.Size(109, 51); + this.SetRawHashes.TabIndex = 27; + this.SetRawHashes.Text = "Установить сырые хеши"; + this.SetRawHashes.UseVisualStyleBackColor = true; + this.SetRawHashes.Click += new System.EventHandler(this.SetRawHashes_Click); + // + // UserPassHash2 + // + this.UserPassHash2.Text = "Хеш пароля 2"; + this.UserPassHash2.Width = 164; // // MainForm // @@ -988,6 +1009,8 @@ internal LinkLabel LinkLabel2 private ContextMenuStrip ContextMenu; private ToolStripMenuItem CopyToolStripMenuItem; internal ColumnHeader ColumnHeader6; + private Button SetRawHashes; + protected internal ColumnHeader UserPassHash2; internal ComboBox cbDBType { diff --git a/PasswordChanger1C/MainForm.cs b/PasswordChanger1C/MainForm.cs index bc48058..da4cdbc 100644 --- a/PasswordChanger1C/MainForm.cs +++ b/PasswordChanger1C/MainForm.cs @@ -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); } @@ -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(); @@ -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 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); + } + } } } \ No newline at end of file diff --git a/PasswordChanger1C/RawHashesPrompt.Designer.cs b/PasswordChanger1C/RawHashesPrompt.Designer.cs index d945ee2..8d017ea 100644 --- a/PasswordChanger1C/RawHashesPrompt.Designer.cs +++ b/PasswordChanger1C/RawHashesPrompt.Designer.cs @@ -106,6 +106,7 @@ private void InitializeComponent() this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "RawHashesPrompt"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Хеши"; this.ResumeLayout(false); this.PerformLayout();