Пример #1
0
 private void passwordSetButton_Click(object sender, EventArgs e)
 {
   passwordCheckDlg passForm = new passwordCheckDlg();
   if (passForm.ShowDialog(this) == DialogResult.OK)
     enteredPassword = passForm.getPass();
 }
Пример #2
0
    private void button1_Click(object sender, EventArgs e)
    {
      filename = null;

      setButton.Enabled = false;
      passwordSetButton.Enabled = false;
      ReadOnlyCheckBox.Enabled = false;

      encryptButton.Enabled = false;
      decryptButton.Enabled = false;

      checkBox1.Enabled = false;
      checkBox2.Enabled = false;
      checkBox3.Enabled = false;
      checkBox4.Enabled = false;
      checkBox5.Enabled = false;
      checkBox6.Enabled = false;
      checkBox7.Enabled = false;

      OpenFileDialog openDialog = new OpenFileDialog();
      openDialog.Title = "Open Project Configuration File";
      openDialog.Filter = "Project Configuration Files|*.spj";
      openDialog.AddExtension = true;
      openDialog.CheckFileExists = true;
      openDialog.CheckPathExists = true;
      if (openDialog.ShowDialog() == DialogResult.OK)
      {
        FileStream fileStream = new FileStream(openDialog.FileName, FileMode.Open);
        StreamReader streamReader = new StreamReader(fileStream);
        string fileString = streamReader.ReadToEnd();
        streamReader.Close();
        fileStream.Close();

        metricHash = GetMetricHash(fileString);

        byte[] passwordHash = null;
        restrictions = "";
        byte[] restrictionCheck = null;

        string[] splitter = { "\r\n" };
        string[] fileStrings = fileString.Split(splitter, StringSplitOptions.RemoveEmptyEntries);

        foreach (string lineString in fileStrings)
        {
          if (lineString.Contains("PasswordHash="))
            passwordHash = GetPasswordHash(lineString);
          else if (lineString.Contains("Restrictions="))
            restrictions = GetRestrictions(lineString);
          else if (lineString.Contains("RestrictionsCheck="))
            restrictionCheck = GetRestrictionsCheck(lineString);
        }

        if (!ValidRestrictionCheck(passwordHash, restrictions, metricHash, restrictionCheck))
        {
          MessageBox.Show("Invalid Restriction Information");
          return;
        }

        if (!PasswordCheck(enteredPassword, passwordHash))
        {
          passwordCheckDlg passForm = new passwordCheckDlg();
          if (passForm.ShowDialog(this) == DialogResult.OK)
            enteredPassword = passForm.getPass();
        }

        if (PasswordCheck(enteredPassword, passwordHash))
        {
          filename = openDialog.FileName;

          setButton.Enabled = true;
          passwordSetButton.Enabled = true;
          ReadOnlyCheckBox.Enabled = true;

          encryptButton.Enabled = true;
          decryptButton.Enabled = true;

          checkBox1.Enabled = true;
          checkBox2.Enabled = true;
          checkBox3.Enabled = true;
          checkBox4.Enabled = true;
          checkBox5.Enabled = true;
          checkBox6.Enabled = true;
          checkBox7.Enabled = true;

          if (restrictions.Contains(ReadOnlyCheckBox.Text))
            ReadOnlyCheckBox.Checked = true;
          else
            ReadOnlyCheckBox.Checked = false;

          if (restrictions.Contains(checkBox1.Text))
            checkBox1.Checked = true;
          else
            checkBox1.Checked = false;

          if (restrictions.Contains(checkBox2.Text))
            checkBox2.Checked = true;
          else
            checkBox2.Checked = false;

          if (restrictions.Contains(checkBox3.Text))
            checkBox3.Checked = true;
          else
            checkBox3.Checked = false;

          if (restrictions.Contains(checkBox4.Text))
            checkBox4.Checked = true;
          else
            checkBox4.Checked = false;

          if (restrictions.Contains(checkBox5.Text))
            checkBox5.Checked = true;
          else
            checkBox5.Checked = false;

          if (restrictions.Contains(checkBox6.Text))
            checkBox6.Checked = true;
          else
            checkBox6.Checked = false;

          if (restrictions.Contains(checkBox7.Text))
            checkBox7.Checked = true;
          else
            checkBox7.Checked = false;

          return;
        }
        else
        {
          MessageBox.Show("Invalid Password");
          return;
        }
      }
    }