Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <time.h>
- #include <Windows.h>
- using namespace System;
- using namespace System::IO;
- using namespace System::Data::OleDb;
- namespace password {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- /// <summary>
- /// Сводка для Form2
- /// </summary>
- public ref class Form2 : public System::Windows::Forms::Form
- {
- public:
- Form2(void)
- {
- InitializeComponent();
- //
- //TODO: добавьте код конструктора
- //
- }
- protected:
- /// <summary>
- /// Освободить все используемые ресурсы.
- /// </summary>
- ~Form2()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::Label^ label1;
- protected:
- private: System::Windows::Forms::TextBox^ textBox1;
- private: System::Windows::Forms::TextBox^ textBox2;
- private: System::Windows::Forms::Button^ button1;
- private: System::Windows::Forms::Label^ label2;
- private: System::Windows::Forms::TextBox^ textBox3;
- private: System::Windows::Forms::CheckBox^ checkBox1;
- private: System::Windows::Forms::Button^ button3;
- private: System::Windows::Forms::Button^ button4;
- private: System::Windows::Forms::TextBox^ textBox4;
- private: System::Windows::Forms::RadioButton^ radioButton1;
- private: System::Windows::Forms::RadioButton^ radioButton2;
- private: System::Windows::Forms::RadioButton^ radioButton3;
- private: System::Windows::Forms::Label^ label3;
- private: System::Windows::Forms::TextBox^ textBox5;
- private:
- /// <summary>
- /// Обязательная переменная конструктора.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Требуемый метод для поддержки конструктора — не изменяйте
- /// содержимое этого метода с помощью редактора кода.
- /// </summary>
- void InitializeComponent(void)
- {
- System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form2::typeid));
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->textBox1 = (gcnew System::Windows::Forms::TextBox());
- this->textBox2 = (gcnew System::Windows::Forms::TextBox());
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->label2 = (gcnew System::Windows::Forms::Label());
- this->textBox3 = (gcnew System::Windows::Forms::TextBox());
- this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
- this->button3 = (gcnew System::Windows::Forms::Button());
- this->button4 = (gcnew System::Windows::Forms::Button());
- this->textBox4 = (gcnew System::Windows::Forms::TextBox());
- this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
- this->radioButton2 = (gcnew System::Windows::Forms::RadioButton());
- this->radioButton3 = (gcnew System::Windows::Forms::RadioButton());
- this->label3 = (gcnew System::Windows::Forms::Label());
- this->textBox5 = (gcnew System::Windows::Forms::TextBox());
- this->SuspendLayout();
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Enabled = false;
- this->label1->Location = System::Drawing::Point(62, 47);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(217, 13);
- this->label1->TabIndex = 0;
- this->label1->Text = L"Введите символы для генерации пароля:";
- //
- // textBox1
- //
- this->textBox1->Location = System::Drawing::Point(65, 63);
- this->textBox1->Name = L"textBox1";
- this->textBox1->Size = System::Drawing::Size(214, 20);
- this->textBox1->TabIndex = 1;
- this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &Form2::textBox1_KeyPress);
- //
- // textBox2
- //
- this->textBox2->Location = System::Drawing::Point(53, 154);
- this->textBox2->Name = L"textBox2";
- this->textBox2->ReadOnly = true;
- this->textBox2->Size = System::Drawing::Size(677, 20);
- this->textBox2->TabIndex = 2;
- //
- // button1
- //
- this->button1->Location = System::Drawing::Point(327, 114);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(154, 34);
- this->button1->TabIndex = 3;
- this->button1->Text = L"Создать пароль";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &Form2::button1_Click);
- //
- // label2
- //
- this->label2->AutoSize = true;
- this->label2->Location = System::Drawing::Point(343, 47);
- this->label2->Name = L"label2";
- this->label2->Size = System::Drawing::Size(138, 13);
- this->label2->TabIndex = 4;
- this->label2->Text = L"Введите кол-во символов";
- //
- // textBox3
- //
- this->textBox3->Location = System::Drawing::Point(346, 63);
- this->textBox3->Name = L"textBox3";
- this->textBox3->Size = System::Drawing::Size(135, 20);
- this->textBox3->TabIndex = 5;
- this->textBox3->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &Form2::textBox3_KeyPress);
- //
- // checkBox1
- //
- this->checkBox1->AutoSize = true;
- this->checkBox1->Location = System::Drawing::Point(569, 47);
- this->checkBox1->Name = L"checkBox1";
- this->checkBox1->Size = System::Drawing::Size(135, 17);
- this->checkBox1->TabIndex = 6;
- this->checkBox1->Text = L"Случайная генерация";
- this->checkBox1->UseVisualStyleBackColor = true;
- this->checkBox1->CheckedChanged += gcnew System::EventHandler(this, &Form2::checkBox1_CheckedChanged);
- //
- // button3
- //
- this->button3->Location = System::Drawing::Point(53, 180);
- this->button3->Name = L"button3";
- this->button3->Size = System::Drawing::Size(154, 34);
- this->button3->TabIndex = 8;
- this->button3->Text = L"Проверить сложность пароля";
- this->button3->UseVisualStyleBackColor = true;
- this->button3->Click += gcnew System::EventHandler(this, &Form2::button3_Click);
- //
- // button4
- //
- this->button4->Location = System::Drawing::Point(537, 180);
- this->button4->Name = L"button4";
- this->button4->Size = System::Drawing::Size(154, 34);
- this->button4->TabIndex = 9;
- this->button4->Text = L"Сохранить пароль";
- this->button4->UseVisualStyleBackColor = true;
- this->button4->Click += gcnew System::EventHandler(this, &Form2::button4_Click);
- //
- // textBox4
- //
- this->textBox4->Location = System::Drawing::Point(53, 220);
- this->textBox4->Name = L"textBox4";
- this->textBox4->Size = System::Drawing::Size(154, 20);
- this->textBox4->TabIndex = 10;
- //
- // radioButton1
- //
- this->radioButton1->AutoSize = true;
- this->radioButton1->Enabled = false;
- this->radioButton1->Location = System::Drawing::Point(537, 70);
- this->radioButton1->Name = L"radioButton1";
- this->radioButton1->Size = System::Drawing::Size(62, 17);
- this->radioButton1->TabIndex = 11;
- this->radioButton1->Text = L"Легкий";
- this->radioButton1->UseVisualStyleBackColor = true;
- //
- // radioButton2
- //
- this->radioButton2->AutoSize = true;
- this->radioButton2->Enabled = false;
- this->radioButton2->Location = System::Drawing::Point(605, 70);
- this->radioButton2->Name = L"radioButton2";
- this->radioButton2->Size = System::Drawing::Size(68, 17);
- this->radioButton2->TabIndex = 11;
- this->radioButton2->Text = L"Средний";
- this->radioButton2->UseVisualStyleBackColor = true;
- //
- // radioButton3
- //
- this->radioButton3->AutoSize = true;
- this->radioButton3->Enabled = false;
- this->radioButton3->Location = System::Drawing::Point(679, 70);
- this->radioButton3->Name = L"radioButton3";
- this->radioButton3->Size = System::Drawing::Size(72, 17);
- this->radioButton3->TabIndex = 11;
- this->radioButton3->Text = L"Сложный";
- this->radioButton3->UseVisualStyleBackColor = true;
- //
- // label3
- //
- this->label3->AutoSize = true;
- this->label3->Location = System::Drawing::Point(364, 223);
- this->label3->Name = L"label3";
- this->label3->Size = System::Drawing::Size(409, 13);
- this->label3->TabIndex = 12;
- this->label3->Text = L"Введите название созданного пароля (можно указать при сохранении пароля)";
- //
- // textBox5
- //
- this->textBox5->Location = System::Drawing::Point(367, 239);
- this->textBox5->Name = L"textBox5";
- this->textBox5->Size = System::Drawing::Size(406, 20);
- this->textBox5->TabIndex = 13;
- //
- // Form2
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"$this.BackgroundImage")));
- this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
- this->ClientSize = System::Drawing::Size(785, 392);
- this->Controls->Add(this->textBox5);
- this->Controls->Add(this->label3);
- this->Controls->Add(this->radioButton3);
- this->Controls->Add(this->radioButton2);
- this->Controls->Add(this->radioButton1);
- this->Controls->Add(this->textBox4);
- this->Controls->Add(this->button4);
- this->Controls->Add(this->button3);
- this->Controls->Add(this->checkBox1);
- this->Controls->Add(this->textBox3);
- this->Controls->Add(this->label2);
- this->Controls->Add(this->button1);
- this->Controls->Add(this->textBox2);
- this->Controls->Add(this->textBox1);
- this->Controls->Add(this->label1);
- this->Name = L"Form2";
- this->Text = L"Form2";
- this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &Form2::Form2_FormClosing);
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- int q = textBox1->Text->Length; //кол-во введённых символов
- String^ z = textBox1->Text;//введённые символы
- int ItogChar[256]; //массив хранящий символы которые сгенерируются
- int w; //номер символа который будет выводиться
- int ic; //номера символов которые были введены
- char a[] ="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
- int j;
- if (((textBox3->Text == "") || (textBox1->Text->Length == 0)) && (checkBox1->Checked == false)) {
- MessageBox::Show("Заполните поле/поля", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Warning);
- }
- else {
- if (checkBox1->Checked == false) {
- j = Convert::ToInt32(textBox3->Text); //кол-во символов которых должно сгенерироваться
- srand(time(NULL));
- textBox2->Text = "";
- for (ic = 0; ic < q; ic++)
- {
- ItogChar[ic] = z[ic];
- };
- ItogChar[ic] = 0;
- for (int i = 0; i < j; i++)
- {
- w = rand() % q;
- textBox2->Text = textBox2->Text + Convert::ToChar(ItogChar[w]);
- };
- }
- };
- if (checkBox1->Checked == true)
- {
- if (radioButton1->Checked == true)
- {
- j = 5;
- textBox2->Text = "";
- for (int i = 0; i < j; i++) {
- w = rand() % 26 - 1;
- textBox2->Text = textBox2->Text + Convert::ToChar(a[w]);
- }
- }
- if (radioButton2->Checked == true)
- {
- j = 9;
- textBox2->Text = "";
- for (int i = 0; i < j; i++) {
- w = rand() % 36 - 1;
- textBox2->Text = textBox2->Text + Convert::ToChar(a[w]);
- }
- }
- if (radioButton3->Checked == true)
- {
- j = 14;
- textBox2->Text = "";
- for (int i = 0; i < j; i++) {
- w = rand() % 62 - 1;
- textBox2->Text = textBox2->Text + Convert::ToChar(a[w]);
- }
- }
- }
- }
- private: System::Void checkBox1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
- if (checkBox1->Checked == true) {
- textBox1->Text = "";
- textBox1->Enabled = false;
- textBox3->Enabled = false;
- radioButton1->Enabled = true;
- radioButton2->Enabled = true;
- radioButton3->Enabled = true;
- textBox3->Text = "";
- }
- else
- {
- textBox1->Enabled = true;
- textBox3->Enabled = true;
- radioButton1->Enabled = false;
- radioButton2->Enabled = false;
- radioButton3->Enabled = false;
- }
- }
- private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
- if ((e->KeyChar < 64 || e->KeyChar > 91) & (e->KeyChar <96 || e->KeyChar > 123) & (e->KeyChar < 47 || e->KeyChar > 58) & (e->KeyChar == 16))
- e->Handled = true;
- }
- private: System::Void textBox3_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
- if ((e->KeyChar <= 9 || e->KeyChar >= 0) & (e->KeyChar == 16))
- e->Handled = true;
- }
- private: System::Void Form2_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e) {
- Application::Exit();
- }
- private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
- if (textBox2->Text->Length == 0)
- {
- MessageBox::Show("Сначала необходимо сгенерировать пароль", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Warning);
- }
- else
- {
- if (textBox2->Text->Length <= 5)
- {
- this->textBox4->ForeColor =Color::Red;
- textBox4->Text = "Пароль слишком простой";
- }
- if ((textBox2->Text->Length >= 6 && textBox2->Text->Length <= 11))
- {
- this->textBox4->ForeColor = Color::Orange;
- textBox4->Text = "Пароль средней сложности";
- }
- if (textBox2->Text->Length >= 12)
- {
- this->textBox4->ForeColor = Color::Green;
- textBox4->Text = "Сложный пароль";
- }
- }
- }
- private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
- if (File::Exists("Source=rezult.mdb")==0) {
- ADOX::Catalog ^ catalogue = gcnew ADOX::CatalogClass();
- try {
- catalogue->Create("Provider=Microsoft.Jet." + "OLEDB.4.0;Data Source=rezult.mdb");
- MessageBox::Show("База данных rezult.mdb успешно создана");
- }
- catch (System::Runtime::InteropServices::COMException ^ error) { }
- finally{ catalogue = nullptr; }
- auto Подключение = gcnew OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=rezult.mdb");
- Подключение->Open();
- auto Команда = gcnew OleDbCommand("CREATE TABLE [БД Пароли] ([Номер п/п] counter, [Созданные пароли] char(20), [Название пароля] char(150))", Подключение);
- try {
- Команда->ExecuteNonQuery();
- //MessageBox::Show( "Структура таблицы 'БД паролей' записана в пустую БД");
- }
- catch (Exception ^ Ситуация)
- {
- }
- Подключение->Close();
- }
- auto Подключение = gcnew OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=rezult.mdb");
- // Открытие подключения:
- Подключение->Open();
- // Создание экземпляра объекта Command с заданием SQL-запроса:
- auto Команда = gcnew OleDbCommand("INSERT INTO [бд Пароли] ([Созданные пароли], [Название пароля]) VALUES ('"+ Convert::ToString(textBox2->Text) +"','"+ Convert::ToString(textBox5->Text)+ "')");
- // Для добавления записи в таблицу БД эта команда обязательна:
- Команда->Connection = Подключение;
- // Выполнение команды SQL:
- Команда->ExecuteNonQuery();
- MessageBox::Show("В таблицу 'БД Паролей' добавлена запись");
- Подключение->Close();
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement