//-----------------------------------------------------------------------Testing private void button_CheckSecureSystem_Click(object sender, EventArgs e) { ActionRegistrator.addRecord(DateTime.Now, Misc.getMethodName(), userName, "ЧЕК СЕКЬЮР СИСТЕМ КЛИК"); using (FileStream fs = new FileStream(PATH_TO_SHA1, FileMode.Open)) { byte[] byteBufferAllFile = new byte[fs.Length]; fs.Read(byteBufferAllFile, 0, byteBufferAllFile.Length); byte[] byteBufferType = new byte[4]; byte[] byteBufferSHA1 = new byte[20]; int count = 0; do { Array.Copy(byteBufferAllFile, count * 24, byteBufferType, 0, 4); Array.Copy(byteBufferAllFile, count * 24 + 4, byteBufferSHA1, 0, 20); byte[] SHA1 = Secure.ComputeHmacsha1(Encoding.UTF8.GetBytes(textBox_passwordCheck.Text), Encoding.UTF8.GetBytes(textBox_userNameCheck.Text + "HELIOSONE")); if (SHA1.SequenceEqual(byteBufferSHA1)) { if (byteBufferType[3] == 1) { textBox_userType.Text = "ADMIN"; } else { if (byteBufferType[3] == 2) { textBox_userType.Text = "SYSTEM"; } else { textBox_userType.Text = "USER"; } } } count++; } while (count < fs.Length / 24); } }
private void buttonLogin_Click(object sender, EventArgs e) { using (FileStream fs = new FileStream(PATH_TO_SHA1, FileMode.Open)) { byte[] byteBufferAllFile = new byte[fs.Length]; fs.Read(byteBufferAllFile, 0, byteBufferAllFile.Length); byte[] byteBufferType = new byte[4]; byte[] byteBufferSHA1 = new byte[20]; int count = 0; do { Array.Copy(byteBufferAllFile, count * 24, byteBufferType, 0, 4); Array.Copy(byteBufferAllFile, count * 24 + 4, byteBufferSHA1, 0, 20); byte[] SHA1 = Secure.ComputeHmacsha1(Encoding.UTF8.GetBytes(textBox_password.Text), Encoding.UTF8.GetBytes(comboBox1.Text + "HELIOSONE")); if (SHA1.SequenceEqual(byteBufferSHA1)) { if (byteBufferType[3] == 0) { userName = comboBox1.Text; userType = 0; break; } if (byteBufferType[3] == 1) { userName = comboBox1.Text; userType = 1; break; } if (byteBufferType[3] == 2) { userName = comboBox1.Text; userType = 2; break; } } else { userType = -1; } count++; } while (count < fs.Length / 24); } if (userType != -1) { ActionRegistrator.addRecord(DateTime.Now, Misc.getMethodName(), userName, "-"); Hide(); } else { userName = (userName == null || userName == "") ? "Неизвестно" : userName; MessageBox.Show("Неверные имя пользователя или пароль", "", MessageBoxButtons.OK, MessageBoxIcon.Stop); ActionRegistrator.addRecord(DateTime.Now, Misc.getMethodName(), userName, "Неудачная попытка входа."); } }