Esempio n. 1
0
        private void btnLog_Click(object sender, EventArgs e)
        {
            Functions b = new Functions();

            // Файл НЕ существует...
            if (!(File.Exists("E:\\3курс(5сем)\\ТОКБ\\WindowsFormsApp1\\test.txt")))
            {
                /*
                 *  1) Генерация ключа.
                 *  2) Шифрование пароля.
                 *  3) Запись в файл.
                 *  4) Открытие формы "LabelKeyForm1".
                 */
                string EncodePas;

                // (1).
                Functions.Key = b.GenKey(txtPas.Text.Length);

                // (2).
                EncodePas = b.Encode(txtPas.Text, Functions.Key);

                // (3).
                b.WriteInFile(EncodePas);

                // (4).
                LabelKeyForm1 f = new LabelKeyForm1();

                this.Hide();
                f.ShowDialog();
                this.Close();
            }
            // Файл существует.
            else
            {
                /*
                 *  1) Передача пароля в конструктор формы "KeyForm".
                 *  2) Открытие формы "KeyForm" для ввода ключа.
                 */

                // (1).
                KeyForm f = new KeyForm(this.txtPas.Text);

                // (2).
                this.Hide();
                f.ShowDialog();
                this.Close();
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Файл НЕ существует.
            if (!(File.Exists("\\test.txt")))
            {
                /*
                 *  1) Генерация ключа.
                 *  2) Шифрование пароля.
                 *  3) Запись в файл.
                 *  4) Открытие формы "LabelKeyForm1".
                 *  5) Открытие формы "LabelKeyForm1".
                 */
                string EncodePas;

                // (1).
                Func.Key = b.GenKey();

                // (2).
                EncodePas = b.Encode(txtPas.Text, Func.Key);

                // (3).
                b.WriteInFile(EncodePas);

                // (4).
                LabelKeyForm1 f = new LabelKeyForm1();

                // (5).
                this.Hide();
                f.ShowDialog();
                this.Close();
            }
            // Файл существует.
            else
            {
                /*
                 *  1) Передача пароля в конструктор формы "KeyForm".
                 *  2) Открытие формы "KeyForm" для ввода ключа.
                 */

                // (1).
                KeyForm f = new KeyForm(this.txtPas.Text);

                // (2).
                this.Hide();
                f.ShowDialog();
                this.Close();
            }
        }
Esempio n. 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Файл НЕ существует.
            if (!(File.Exists("D:\\Univer\\ТОКБ\\WindowsFormsApp1\\Not_key.txt")))
            {
                string EncodePas, Key;

                // 1) Генерация ключа.
                Key = b.GenKey();

                // 2) Шифрование пароля.
                EncodePas = b.Encode(txtPas.Text, Key);

                // 3) Запись в файл.
                b.WriteInFile(EncodePas);

                // 4) Передача ключа в конструктор формы "LabelKeyForm1".
                LabelKeyForm1 f = new LabelKeyForm1(Key);

                // 5) Открытие формы "LabelKeyForm1".
                this.Hide();
                f.ShowDialog();
                this.Close();
            }
            // Файл существует.
            else
            {
                // 1) Передача пароля в конструктор формы "KeyForm".
                KeyForm f = new KeyForm(this.txtPas.Text);

                // 2) Открытие формы "KeyForm" для ввода ключа.
                this.Hide();
                f.ShowDialog();
                this.Close();
            }
        }
Esempio n. 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            Func.FlashDrive = comboBox1.Text.Remove(2);
            Func.Pas        = txtPas.Text;


            if (!(File.Exists("\\test.txt")))
            {
                string EncodePas;

                Func.Key = b.GenKey();

                EncodePas = b.Encode(txtPas.Text, Func.Key);

                b.WriteInFile(EncodePas);

                // запись на флешку
                SafeFileHandle handle = CreateFile(
                    lpFileName: @"\\.\" + Func.FlashDrive,
                    dwDesiredAccess: FileAccess.Read,
                    dwShareMode: FileShare.ReadWrite,
                    lpSecurityAttributes: IntPtr.Zero,
                    dwCreationDisposition: System.IO.FileMode.OpenOrCreate,
                    dwFlagsAndAttributes: FileAttributes.Normal,
                    hTemplateFile: IntPtr.Zero);

                using (FileStream disk = new FileStream(handle, FileAccess.Read))
                {
                    mbrData = new byte[512];
                    disk.Read(mbrData, 0, 512);
                }

                handle = CreateFile(
                    lpFileName: @"\\.\" + Func.FlashDrive,
                    dwDesiredAccess: FileAccess.Write,
                    dwShareMode: FileShare.ReadWrite,
                    lpSecurityAttributes: IntPtr.Zero,
                    dwCreationDisposition: System.IO.FileMode.OpenOrCreate,
                    dwFlagsAndAttributes: FileAttributes.Normal,
                    hTemplateFile: IntPtr.Zero);

                using (FileStream disk = new FileStream(handle, FileAccess.Write))
                {
                    for (int i = 0; i < EncodePas.Length; i++)
                    {
                        mbrData[384 + i] = (byte)EncodePas[i];
                    }

                    disk.Write(mbrData, 0, 512);
                }

                this.Hide();
                LabelKeyForm1 f = new LabelKeyForm1();
                f.ShowDialog();
                this.Close();
            }
            else
            {
                KeyForm f = new KeyForm();

                this.Hide();
                f.ShowDialog();
                this.Close();
            }
        }
Esempio n. 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            Func.FlashDrive = comboBox1.Text.Remove(2);
            Func.Pas        = txtPas.Text;

            // Файл НЕ существует.
            if (!(File.Exists("\\test.txt")))
            {
                /*
                 *  1) Генерация ключа.
                 *  2) Шифрование пароля.
                 *  3) Запись в  файл.
                 *  4) Запись на флешку.
                 *  5) Открытие формы "LabelKeyForm1".
                 */
                string EncodePas;

                // (1).
                Func.Key = b.GenKey();

                // (2).
                EncodePas = b.Encode(txtPas.Text, Func.Key);

                // (3).
                b.WriteInFile(EncodePas);

                // (4).
                SafeFileHandle handle = CreateFile(
                    lpFileName: @"\\.\" + Func.FlashDrive,
                    dwDesiredAccess: FileAccess.Read,
                    dwShareMode: FileShare.ReadWrite,
                    lpSecurityAttributes: IntPtr.Zero,
                    dwCreationDisposition: System.IO.FileMode.OpenOrCreate,
                    dwFlagsAndAttributes: FileAttributes.Normal,
                    hTemplateFile: IntPtr.Zero);

                using (FileStream disk = new FileStream(handle, FileAccess.Read))
                {
                    mbrData = new byte[512];
                    disk.Read(mbrData, 0, 512);
                }

                handle = CreateFile(
                    lpFileName: @"\\.\" + Func.FlashDrive,
                    dwDesiredAccess: FileAccess.Write,
                    dwShareMode: FileShare.ReadWrite,
                    lpSecurityAttributes: IntPtr.Zero,
                    dwCreationDisposition: System.IO.FileMode.OpenOrCreate,
                    dwFlagsAndAttributes: FileAttributes.Normal,
                    hTemplateFile: IntPtr.Zero);

                using (FileStream disk = new FileStream(handle, FileAccess.Write))
                {
                    for (int i = 0; i < EncodePas.Length; i++)
                    {
                        mbrData[384 + i] = (byte)EncodePas[i];
                    }

                    disk.Write(mbrData, 0, 512);
                }

                // (5).
                this.Hide();
                LabelKeyForm1 f = new LabelKeyForm1();
                f.ShowDialog();
                this.Close();
            }
            // Файл существует.
            else
            {
                /*
                 *  1) Передача пароля в конструктор формы "KeyForm".
                 *  2) Открытие формы "KeyForm" для ввода ключа.
                 */

                // (1).
                KeyForm f = new KeyForm();

                // (2).
                this.Hide();
                f.ShowDialog();
                this.Close();
            }
        }