예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            /*
             * string oldpas = textBox1.Text;
             * string newpas = textBox2.Text;
             * string pass;
             * FileStream file = new FileStream(kl.Dir + "pass.txt", FileMode.Open);
             * StreamReader reader = new StreamReader(file);
             * pass = reader.ReadLine();
             * reader.Close();
             * oldpas = Encode(oldpas, kl.Val);
             * if (pass == oldpas)
             * {
             *  FileStream wfile = new FileStream(kl.Dir + "pass.txt", FileMode.Truncate);
             *  StreamWriter writer = new StreamWriter(wfile);
             *  Random rnd = new Random();
             *  int i = 1 + rnd.Next(100);
             *  newpas = Encode(newpas, GenerateKeyWord(newpas.Length, i));
             *  writer.WriteLine(newpas);
             *  writer.Close();
             *  MessageBox.Show("Your new key: " + GenerateKeyWord(newpas.Length, i));
             *  kl.Val = GenerateKeyWord(newpas.Length, i);
             * }
             * else
             * {
             *  i--;
             *  MessageBox.Show("Wrong password or key! You have " + i + " chances!");
             * }
             */

            string oldpas  = textBox1.Text;
            string newpas  = textBox2.Text;
            string drive   = "\\\\.\\" + kl.Dir;
            string codpass = Encode(oldpas, kl.Val);; //кодирование пароля

            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();

                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)
                {
                    if (fr.OpenWrite(drive))
                    {
                        string codnewpass;
                        codnewpass = null;
                        Random rnd = new Random();
                        int    l   = 1 + rnd.Next(100);
                        kl.Val = GenerateKeyWord(newpas.Length, l);
                        MessageBox.Show("Your key: " + kl.Val);
                        codnewpass = Encode(newpas, kl.Val);
                        byte[] newpass = new byte[8];
                        for (int i = 0; i < codnewpass.Length; i++)
                        {
                            newpass[i] = (byte)codnewpass[i];
                        }
                        for (int i = 54; i < 62; i++)
                        {
                            ByteBuffer[i] = newpass[i - 54];
                        }
                        fr.Write(ByteBuffer, 0, 512);
                        this.Hide();
                        MessageBox.Show("Пароль сменен");

                        Application.Exit();
                    }
                }
                else
                {
                    MessageBox.Show("Попыток:" + i);
                    i--;
                    if (i < 1)
                    {
                        Application.Exit();
                    }
                    codpass = null;
                    temp    = null;
                    oldpass = null;
                    textBox1.Clear();
                    textBox2.Clear();
                }
            }
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string oldpas  = textBox1.Text;
            string newpas  = textBox2.Text;
            string drive   = "\\\\.\\" + kl.Dir;
            string codpass = Encode(oldpas, kl.Val);; //кодирование пароля

            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();

                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)
                {
                    if (fr.OpenWrite(drive))
                    {
                        string codnewpass;
                        codnewpass = null;
                        Random rnd = new Random();
                        int    l   = 1 + rnd.Next(100);
                        kl.Val = GenerateKeyWord(newpas.Length, l);
                        MessageBox.Show("Your key: " + kl.Val);
                        codnewpass = Encode(newpas, kl.Val);
                        byte[] newpass = new byte[8];
                        for (int i = 0; i < codnewpass.Length; i++)
                        {
                            newpass[i] = (byte)codnewpass[i];
                        }
                        for (int i = 54; i < 62; i++)
                        {
                            ByteBuffer[i] = newpass[i - 54];
                        }
                        fr.Write(ByteBuffer, 0, 512);
                        this.Hide();
                        MessageBox.Show("Пароль сменен");

                        Application.Exit();
                    }
                }
                else
                {
                    MessageBox.Show("Попыток:" + i);
                    i--;
                    if (i < 1)
                    {
                        Application.Exit();
                    }
                    codpass = null;
                    temp    = null;
                    oldpass = null;
                    textBox1.Clear();
                    textBox2.Clear();
                }
            }
        }
예제 #3
0
파일: Form1.cs 프로젝트: YuTiiS/tokblabs
        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();
                    }
                }
            }
        }
예제 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            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();
                    }
                }
            }
        }