Advertisement
Guest User

Untitled

a guest
Jun 6th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.03 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <time.h>
  3. #include <Windows.h>
  4. using namespace System;
  5. using namespace System::IO;
  6. using namespace System::Data::OleDb;
  7. namespace password {
  8.  
  9. using namespace System;
  10. using namespace System::ComponentModel;
  11. using namespace System::Collections;
  12. using namespace System::Windows::Forms;
  13. using namespace System::Data;
  14. using namespace System::Drawing;
  15.  
  16. /// <summary>
  17. /// Сводка для Form2
  18. /// </summary>
  19. public ref class Form2 : public System::Windows::Forms::Form
  20. {
  21. public:
  22. Form2(void)
  23. {
  24. InitializeComponent();
  25. //
  26. //TODO: добавьте код конструктора
  27. //
  28. }
  29.  
  30. protected:
  31. /// <summary>
  32. /// Освободить все используемые ресурсы.
  33. /// </summary>
  34. ~Form2()
  35. {
  36. if (components)
  37. {
  38. delete components;
  39. }
  40. }
  41. private: System::Windows::Forms::Label^ label1;
  42. protected:
  43. private: System::Windows::Forms::TextBox^ textBox1;
  44. private: System::Windows::Forms::TextBox^ textBox2;
  45. private: System::Windows::Forms::Button^ button1;
  46. private: System::Windows::Forms::Label^ label2;
  47. private: System::Windows::Forms::TextBox^ textBox3;
  48. private: System::Windows::Forms::CheckBox^ checkBox1;
  49.  
  50. private: System::Windows::Forms::Button^ button3;
  51. private: System::Windows::Forms::Button^ button4;
  52. private: System::Windows::Forms::TextBox^ textBox4;
  53. private: System::Windows::Forms::RadioButton^ radioButton1;
  54. private: System::Windows::Forms::RadioButton^ radioButton2;
  55. private: System::Windows::Forms::RadioButton^ radioButton3;
  56. private: System::Windows::Forms::Label^ label3;
  57. private: System::Windows::Forms::TextBox^ textBox5;
  58.  
  59. private:
  60. /// <summary>
  61. /// Обязательная переменная конструктора.
  62. /// </summary>
  63. System::ComponentModel::Container ^components;
  64.  
  65. #pragma region Windows Form Designer generated code
  66. /// <summary>
  67. /// Требуемый метод для поддержки конструктора — не изменяйте
  68. /// содержимое этого метода с помощью редактора кода.
  69. /// </summary>
  70. void InitializeComponent(void)
  71. {
  72. System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form2::typeid));
  73. this->label1 = (gcnew System::Windows::Forms::Label());
  74. this->textBox1 = (gcnew System::Windows::Forms::TextBox());
  75. this->textBox2 = (gcnew System::Windows::Forms::TextBox());
  76. this->button1 = (gcnew System::Windows::Forms::Button());
  77. this->label2 = (gcnew System::Windows::Forms::Label());
  78. this->textBox3 = (gcnew System::Windows::Forms::TextBox());
  79. this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
  80. this->button3 = (gcnew System::Windows::Forms::Button());
  81. this->button4 = (gcnew System::Windows::Forms::Button());
  82. this->textBox4 = (gcnew System::Windows::Forms::TextBox());
  83. this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
  84. this->radioButton2 = (gcnew System::Windows::Forms::RadioButton());
  85. this->radioButton3 = (gcnew System::Windows::Forms::RadioButton());
  86. this->label3 = (gcnew System::Windows::Forms::Label());
  87. this->textBox5 = (gcnew System::Windows::Forms::TextBox());
  88. this->SuspendLayout();
  89. //
  90. // label1
  91. //
  92. this->label1->AutoSize = true;
  93. this->label1->Enabled = false;
  94. this->label1->Location = System::Drawing::Point(62, 47);
  95. this->label1->Name = L"label1";
  96. this->label1->Size = System::Drawing::Size(217, 13);
  97. this->label1->TabIndex = 0;
  98. this->label1->Text = L"Введите символы для генерации пароля:";
  99. //
  100. // textBox1
  101. //
  102. this->textBox1->Location = System::Drawing::Point(65, 63);
  103. this->textBox1->Name = L"textBox1";
  104. this->textBox1->Size = System::Drawing::Size(214, 20);
  105. this->textBox1->TabIndex = 1;
  106. this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &Form2::textBox1_KeyPress);
  107. //
  108. // textBox2
  109. //
  110. this->textBox2->Location = System::Drawing::Point(53, 154);
  111. this->textBox2->Name = L"textBox2";
  112. this->textBox2->ReadOnly = true;
  113. this->textBox2->Size = System::Drawing::Size(677, 20);
  114. this->textBox2->TabIndex = 2;
  115. //
  116. // button1
  117. //
  118. this->button1->Location = System::Drawing::Point(327, 114);
  119. this->button1->Name = L"button1";
  120. this->button1->Size = System::Drawing::Size(154, 34);
  121. this->button1->TabIndex = 3;
  122. this->button1->Text = L"Создать пароль";
  123. this->button1->UseVisualStyleBackColor = true;
  124. this->button1->Click += gcnew System::EventHandler(this, &Form2::button1_Click);
  125. //
  126. // label2
  127. //
  128. this->label2->AutoSize = true;
  129. this->label2->Location = System::Drawing::Point(343, 47);
  130. this->label2->Name = L"label2";
  131. this->label2->Size = System::Drawing::Size(138, 13);
  132. this->label2->TabIndex = 4;
  133. this->label2->Text = L"Введите кол-во символов";
  134. //
  135. // textBox3
  136. //
  137. this->textBox3->Location = System::Drawing::Point(346, 63);
  138. this->textBox3->Name = L"textBox3";
  139. this->textBox3->Size = System::Drawing::Size(135, 20);
  140. this->textBox3->TabIndex = 5;
  141. this->textBox3->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &Form2::textBox3_KeyPress);
  142. //
  143. // checkBox1
  144. //
  145. this->checkBox1->AutoSize = true;
  146. this->checkBox1->Location = System::Drawing::Point(569, 47);
  147. this->checkBox1->Name = L"checkBox1";
  148. this->checkBox1->Size = System::Drawing::Size(135, 17);
  149. this->checkBox1->TabIndex = 6;
  150. this->checkBox1->Text = L"Случайная генерация";
  151. this->checkBox1->UseVisualStyleBackColor = true;
  152. this->checkBox1->CheckedChanged += gcnew System::EventHandler(this, &Form2::checkBox1_CheckedChanged);
  153. //
  154. // button3
  155. //
  156. this->button3->Location = System::Drawing::Point(53, 180);
  157. this->button3->Name = L"button3";
  158. this->button3->Size = System::Drawing::Size(154, 34);
  159. this->button3->TabIndex = 8;
  160. this->button3->Text = L"Проверить сложность пароля";
  161. this->button3->UseVisualStyleBackColor = true;
  162. this->button3->Click += gcnew System::EventHandler(this, &Form2::button3_Click);
  163. //
  164. // button4
  165. //
  166. this->button4->Location = System::Drawing::Point(537, 180);
  167. this->button4->Name = L"button4";
  168. this->button4->Size = System::Drawing::Size(154, 34);
  169. this->button4->TabIndex = 9;
  170. this->button4->Text = L"Сохранить пароль";
  171. this->button4->UseVisualStyleBackColor = true;
  172. this->button4->Click += gcnew System::EventHandler(this, &Form2::button4_Click);
  173. //
  174. // textBox4
  175. //
  176. this->textBox4->Location = System::Drawing::Point(53, 220);
  177. this->textBox4->Name = L"textBox4";
  178. this->textBox4->Size = System::Drawing::Size(154, 20);
  179. this->textBox4->TabIndex = 10;
  180. //
  181. // radioButton1
  182. //
  183. this->radioButton1->AutoSize = true;
  184. this->radioButton1->Enabled = false;
  185. this->radioButton1->Location = System::Drawing::Point(537, 70);
  186. this->radioButton1->Name = L"radioButton1";
  187. this->radioButton1->Size = System::Drawing::Size(62, 17);
  188. this->radioButton1->TabIndex = 11;
  189. this->radioButton1->Text = L"Легкий";
  190. this->radioButton1->UseVisualStyleBackColor = true;
  191. //
  192. // radioButton2
  193. //
  194. this->radioButton2->AutoSize = true;
  195. this->radioButton2->Enabled = false;
  196. this->radioButton2->Location = System::Drawing::Point(605, 70);
  197. this->radioButton2->Name = L"radioButton2";
  198. this->radioButton2->Size = System::Drawing::Size(68, 17);
  199. this->radioButton2->TabIndex = 11;
  200. this->radioButton2->Text = L"Средний";
  201. this->radioButton2->UseVisualStyleBackColor = true;
  202. //
  203. // radioButton3
  204. //
  205. this->radioButton3->AutoSize = true;
  206. this->radioButton3->Enabled = false;
  207. this->radioButton3->Location = System::Drawing::Point(679, 70);
  208. this->radioButton3->Name = L"radioButton3";
  209. this->radioButton3->Size = System::Drawing::Size(72, 17);
  210. this->radioButton3->TabIndex = 11;
  211. this->radioButton3->Text = L"Сложный";
  212. this->radioButton3->UseVisualStyleBackColor = true;
  213. //
  214. // label3
  215. //
  216. this->label3->AutoSize = true;
  217. this->label3->Location = System::Drawing::Point(364, 223);
  218. this->label3->Name = L"label3";
  219. this->label3->Size = System::Drawing::Size(409, 13);
  220. this->label3->TabIndex = 12;
  221. this->label3->Text = L"Введите название созданного пароля (можно указать при сохранении пароля)";
  222. //
  223. // textBox5
  224. //
  225. this->textBox5->Location = System::Drawing::Point(367, 239);
  226. this->textBox5->Name = L"textBox5";
  227. this->textBox5->Size = System::Drawing::Size(406, 20);
  228. this->textBox5->TabIndex = 13;
  229. //
  230. // Form2
  231. //
  232. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  233. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  234. this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"$this.BackgroundImage")));
  235. this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
  236. this->ClientSize = System::Drawing::Size(785, 392);
  237. this->Controls->Add(this->textBox5);
  238. this->Controls->Add(this->label3);
  239. this->Controls->Add(this->radioButton3);
  240. this->Controls->Add(this->radioButton2);
  241. this->Controls->Add(this->radioButton1);
  242. this->Controls->Add(this->textBox4);
  243. this->Controls->Add(this->button4);
  244. this->Controls->Add(this->button3);
  245. this->Controls->Add(this->checkBox1);
  246. this->Controls->Add(this->textBox3);
  247. this->Controls->Add(this->label2);
  248. this->Controls->Add(this->button1);
  249. this->Controls->Add(this->textBox2);
  250. this->Controls->Add(this->textBox1);
  251. this->Controls->Add(this->label1);
  252. this->Name = L"Form2";
  253. this->Text = L"Form2";
  254. this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &Form2::Form2_FormClosing);
  255. this->ResumeLayout(false);
  256. this->PerformLayout();
  257.  
  258. }
  259. #pragma endregion
  260. private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
  261. int q = textBox1->Text->Length; //кол-во введённых символов
  262. String^ z = textBox1->Text;//введённые символы
  263.  
  264. int ItogChar[256]; //массив хранящий символы которые сгенерируются
  265. int w; //номер символа который будет выводиться
  266. int ic; //номера символов которые были введены
  267. char a[] ="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
  268. int j;
  269. if (((textBox3->Text == "") || (textBox1->Text->Length == 0)) && (checkBox1->Checked == false)) {
  270. MessageBox::Show("Заполните поле/поля", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Warning);
  271. }
  272. else {
  273.  
  274. if (checkBox1->Checked == false) {
  275. j = Convert::ToInt32(textBox3->Text); //кол-во символов которых должно сгенерироваться
  276. srand(time(NULL));
  277. textBox2->Text = "";
  278. for (ic = 0; ic < q; ic++)
  279. {
  280. ItogChar[ic] = z[ic];
  281. };
  282. ItogChar[ic] = 0;
  283.  
  284. for (int i = 0; i < j; i++)
  285. {
  286. w = rand() % q;
  287. textBox2->Text = textBox2->Text + Convert::ToChar(ItogChar[w]);
  288. };
  289. }
  290. };
  291. if (checkBox1->Checked == true)
  292. {
  293. if (radioButton1->Checked == true)
  294. {
  295. j = 5;
  296. textBox2->Text = "";
  297. for (int i = 0; i < j; i++) {
  298. w = rand() % 26 - 1;
  299. textBox2->Text = textBox2->Text + Convert::ToChar(a[w]);
  300. }
  301. }
  302. if (radioButton2->Checked == true)
  303. {
  304. j = 9;
  305. textBox2->Text = "";
  306. for (int i = 0; i < j; i++) {
  307. w = rand() % 36 - 1;
  308. textBox2->Text = textBox2->Text + Convert::ToChar(a[w]);
  309. }
  310. }
  311. if (radioButton3->Checked == true)
  312. {
  313. j = 14;
  314. textBox2->Text = "";
  315. for (int i = 0; i < j; i++) {
  316. w = rand() % 62 - 1;
  317. textBox2->Text = textBox2->Text + Convert::ToChar(a[w]);
  318. }
  319. }
  320. }
  321. }
  322. private: System::Void checkBox1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
  323. if (checkBox1->Checked == true) {
  324. textBox1->Text = "";
  325. textBox1->Enabled = false;
  326. textBox3->Enabled = false;
  327. radioButton1->Enabled = true;
  328. radioButton2->Enabled = true;
  329. radioButton3->Enabled = true;
  330. textBox3->Text = "";
  331. }
  332. else
  333. {
  334. textBox1->Enabled = true;
  335. textBox3->Enabled = true;
  336. radioButton1->Enabled = false;
  337. radioButton2->Enabled = false;
  338. radioButton3->Enabled = false;
  339. }
  340. }
  341. private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
  342. if ((e->KeyChar < 64 || e->KeyChar > 91) & (e->KeyChar <96 || e->KeyChar > 123) & (e->KeyChar < 47 || e->KeyChar > 58) & (e->KeyChar == 16))
  343. e->Handled = true;
  344. }
  345. private: System::Void textBox3_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
  346. if ((e->KeyChar <= 9 || e->KeyChar >= 0) & (e->KeyChar == 16))
  347. e->Handled = true;
  348. }
  349. private: System::Void Form2_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e) {
  350. Application::Exit();
  351. }
  352. private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
  353. if (textBox2->Text->Length == 0)
  354. {
  355. MessageBox::Show("Сначала необходимо сгенерировать пароль", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Warning);
  356. }
  357. else
  358. {
  359. if (textBox2->Text->Length <= 5)
  360. {
  361. this->textBox4->ForeColor =Color::Red;
  362. textBox4->Text = "Пароль слишком простой";
  363. }
  364.  
  365. if ((textBox2->Text->Length >= 6 && textBox2->Text->Length <= 11))
  366. {
  367. this->textBox4->ForeColor = Color::Orange;
  368. textBox4->Text = "Пароль средней сложности";
  369. }
  370. if (textBox2->Text->Length >= 12)
  371. {
  372. this->textBox4->ForeColor = Color::Green;
  373. textBox4->Text = "Сложный пароль";
  374. }
  375. }
  376.  
  377. }
  378. private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
  379. if (File::Exists("Source=rezult.mdb")==0) {
  380. ADOX::Catalog ^ catalogue = gcnew ADOX::CatalogClass();
  381. try {
  382. catalogue->Create("Provider=Microsoft.Jet." + "OLEDB.4.0;Data Source=rezult.mdb");
  383. MessageBox::Show("База данных rezult.mdb успешно создана");
  384. }
  385. catch (System::Runtime::InteropServices::COMException ^ error) { }
  386. finally{ catalogue = nullptr; }
  387.  
  388. auto Подключение = gcnew OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=rezult.mdb");
  389. Подключение->Open();
  390. auto Команда = gcnew OleDbCommand("CREATE TABLE [БД Пароли] ([Номер п/п] counter, [Созданные пароли] char(20), [Название пароля] char(150))", Подключение);
  391. try {
  392. Команда->ExecuteNonQuery();
  393. //MessageBox::Show( "Структура таблицы 'БД паролей' записана в пустую БД");
  394. }
  395. catch (Exception ^ Ситуация)
  396. {
  397. }
  398. Подключение->Close();
  399. }
  400. auto Подключение = gcnew OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=rezult.mdb");
  401. // Открытие подключения:
  402. Подключение->Open();
  403. // Создание экземпляра объекта Command с заданием SQL-запроса:
  404. auto Команда = gcnew OleDbCommand("INSERT INTO [бд Пароли] ([Созданные пароли], [Название пароля]) VALUES ('"+ Convert::ToString(textBox2->Text) +"','"+ Convert::ToString(textBox5->Text)+ "')");
  405. // Для добавления записи в таблицу БД эта команда обязательна:
  406. Команда->Connection = Подключение;
  407. // Выполнение команды SQL:
  408. Команда->ExecuteNonQuery();
  409. MessageBox::Show("В таблицу 'БД Паролей' добавлена запись");
  410. Подключение->Close();
  411.  
  412.  
  413. }
  414. };
  415. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement