Exemplo n.º 1
0
 public Form2(key K)
 {
     InitializeComponent();
     kl = K;
 }
Exemplo n.º 2
0
 public Form2(key Key)
 {
     InitializeComponent();
     kl = Key;
 }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            /*if (Directory.Exists(str))
             * {
             *  string pas = textBox1.Text;
             *  string pass;
             *  FileInfo fileInf = new FileInfo(str + "pass.txt");
             *  if (fileInf.Exists)
             *  {
             *      FileStream file = new FileStream(str + "pass.txt", FileMode.Open);
             *      StreamReader reader = new StreamReader(file);
             *      pass = reader.ReadLine();
             *      reader.Close();
             *      key Key = new key();
             *      Key.Val = textBox2.Text;
             *      Key.Dir = str;
             *      pas = Encode(pas, Key.Val);
             *      if (pas == pass)
             *      {
             *          Form ifrm = new Form2(Key);
             *          ifrm.Show();
             *          this.Hide();
             *      }
             *      else
             *      {
             *          i--;
             *          MessageBox.Show("Wrong password or key! You have " + i + " chances!");
             *      }
             *  }
             *  else
             *  {
             *      FileStream file = new FileStream(str + "pass.txt", FileMode.Create);
             *      StreamWriter writer = new StreamWriter(file);
             *      Random rnd = new Random();
             *      int i = 1 + rnd.Next(100);
             *      pas = Encode(pas, GenerateKeyWord(pas.Length, i));
             *      writer.WriteLine(pas);
             *      MessageBox.Show("Your key: " + GenerateKeyWord(pas.Length, i));
             *      writer.Close();
             *      key Key = new key();
             *      Key.Val = GenerateKeyWord(pas.Length, i);
             *      Key.Dir = str;
             *      Form ifrm = new Form2(Key);
             *      ifrm.Show();
             *      this.Hide();
             *  }
             *  if (i == 0)
             *  {
             *      this.Close();
             *  }
             * }
             * else
             * {
             *  MessageBox.Show("Dir doesn't exist!");
             * }*/

            string password_1 = "";

            password_1 = textBox1.Text;
            string drive = "\\\\.\\" + comboBox1.Text.Remove(2);
            string pas   = textBox1.Text;
            key    Key   = new key();

            Key.Dir = comboBox1.Text.Remove(2);;
            byte[]     ByteBuffer = new byte[512];//задаем размер буфера
            byte[]     temp       = new byte[8];
            bool       flag       = true;
            FileReader fr         = new FileReader();

            if (fr.OpenRead(drive)) //вызов для чтения
            {
                int count = fr.Read(ByteBuffer, 512);

                for (int i = 54; i < 62; i++)
                {
                    temp[i - 54] = ByteBuffer[i];
                }
                fr.Close();

                if (temp[0] == 0)//пароль еще не записан на флешке
                {
                    fr.OpenWrite(drive);
                    {
                        Random rnd = new Random();
                        int    l   = 1 + rnd.Next(100);
                        Key.Val = GenerateKeyWord(pas.Length, l);
                        MessageBox.Show("Your key: " + Key.Val);
                        string codpass = Encode(pas, Key.Val);
                        byte[] oldpass = new byte[8];
                        for (int i = 0; i < codpass.Length; i++)
                        {
                            oldpass[i] = (byte)codpass[i];
                        }
                        for (int i = 54; i < 62; i++)
                        {
                            ByteBuffer[i] = oldpass[i - 54];
                        }
                        count = fr.Write(ByteBuffer, 0, 512);
                        this.Hide();
                        Form2 f = new Form2(Key); //Вывод на экран окна успешного ввода
                        f.Show();
                    }
                    fr.Close();
                }
                else
                {
                    Key.Val = textBox2.Text;
                    string codpass = Encode(pas, Key.Val);
                    byte[] oldpass = new byte[8];
                    for (int i = 0; i < codpass.Length; i++)
                    {
                        oldpass[i] = (byte)codpass[i];
                    }
                    for (int i = 0; i < 8; i++)
                    {
                        if (temp[i] != oldpass[i])
                        {
                            flag = false;
                        }
                    }
                    if (flag != false)
                    {
                        // codpass = null;
                        //System.Diagnostics.Process.Start(@"h:\\");
                        this.Hide();
                        Form2 f = new Form2(Key); //Вывод на экран окна успешного ввода
                        f.Show();
                    }
                    else
                    {
                        MessageBox.Show("Попыток:" + i);
                        i--;
                        if (i < 1)
                        {
                            Application.Exit();
                        }
                        textBox1.Clear();
                    }
                }
            }
        }