Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.05 KB | None | 0 0
  1. //////// MyForm.h ///////////////////////////////
  2.  
  3. #pragma once
  4. #include "globalvariable.h"
  5. #include "MainForm.h"
  6.  
  7. namespace CppWinForm3 {
  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. /// Summary for MyForm
  18. /// </summary>
  19. public ref class MyForm : public System::Windows::Forms::Form
  20. {
  21. public:
  22. MyForm(void)
  23. {
  24. InitializeComponent();
  25. //
  26. //TODO: Add the constructor code here
  27. //
  28. }
  29.  
  30. protected:
  31. /// <summary>
  32. /// Clean up any resources being used.
  33. /// </summary>
  34. ~MyForm()
  35. {
  36. if (components)
  37. {
  38. delete components;
  39. }
  40. }
  41. private: System::Windows::Forms::Button^ login;
  42. private: System::Windows::Forms::TextBox^ iuser;
  43. private: System::Windows::Forms::TextBox^ ipass;
  44.  
  45.  
  46.  
  47. protected:
  48.  
  49. protected:
  50.  
  51.  
  52.  
  53. private: System::Windows::Forms::Label^ label1;
  54. private: System::Windows::Forms::Label^ label2;
  55. private: System::Windows::Forms::Button^ exit;
  56.  
  57. private:
  58. /// <summary>
  59. /// Required designer variable.
  60. /// </summary>
  61. System::ComponentModel::Container ^components;
  62.  
  63. #pragma region Windows Form Designer generated code
  64. /// <summary>
  65. /// Required method for Designer support - do not modify
  66. /// the contents of this method with the code editor.
  67. /// </summary>
  68. void InitializeComponent(void)
  69. {
  70. this->login = (gcnew System::Windows::Forms::Button());
  71. this->iuser = (gcnew System::Windows::Forms::TextBox());
  72. this->ipass = (gcnew System::Windows::Forms::TextBox());
  73. this->label1 = (gcnew System::Windows::Forms::Label());
  74. this->label2 = (gcnew System::Windows::Forms::Label());
  75. this->exit = (gcnew System::Windows::Forms::Button());
  76. this->SuspendLayout();
  77. //
  78. // login
  79. //
  80. this->login->BackColor = System::Drawing::SystemColors::ControlLight;
  81. this->login->FlatAppearance->BorderSize = 0;
  82. this->login->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
  83. this->login->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  84. static_cast<System::Byte>(0)));
  85. this->login->ForeColor = System::Drawing::SystemColors::ActiveCaptionText;
  86. this->login->Location = System::Drawing::Point(89, 150);
  87. this->login->Name = L"login";
  88. this->login->Size = System::Drawing::Size(94, 36);
  89. this->login->TabIndex = 3;
  90. this->login->Text = L"Entrar";
  91. this->login->UseVisualStyleBackColor = false;
  92. this->login->Click += gcnew System::EventHandler(this, &MyForm::login_Click);
  93. //
  94. // iuser
  95. //
  96. this->iuser->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
  97. this->iuser->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  98. static_cast<System::Byte>(0)));
  99. this->iuser->Location = System::Drawing::Point(148, 40);
  100. this->iuser->Name = L"iuser";
  101. this->iuser->Size = System::Drawing::Size(206, 29);
  102. this->iuser->TabIndex = 1;
  103. this->iuser->TextChanged += gcnew System::EventHandler(this, &MyForm::iuser_TextChanged);
  104. //
  105. // ipass
  106. //
  107. this->ipass->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
  108. this->ipass->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  109. static_cast<System::Byte>(0)));
  110. this->ipass->Location = System::Drawing::Point(148, 84);
  111. this->ipass->Name = L"ipass";
  112. this->ipass->PasswordChar = '*';
  113. this->ipass->Size = System::Drawing::Size(206, 29);
  114. this->ipass->TabIndex = 2;
  115. this->ipass->TextChanged += gcnew System::EventHandler(this, &MyForm::ipass_TextChanged);
  116. //
  117. // label1
  118. //
  119. this->label1->AccessibleDescription = L"";
  120. this->label1->AutoSize = true;
  121. this->label1->BackColor = System::Drawing::SystemColors::Control;
  122. this->label1->FlatStyle = System::Windows::Forms::FlatStyle::Popup;
  123. this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  124. static_cast<System::Byte>(0)));
  125. this->label1->Location = System::Drawing::Point(33, 43);
  126. this->label1->Name = L"label1";
  127. this->label1->Size = System::Drawing::Size(74, 24);
  128. this->label1->TabIndex = 4;
  129. this->label1->Text = L"Usuario";
  130. this->label1->Click += gcnew System::EventHandler(this, &MyForm::label1_Click);
  131. //
  132. // label2
  133. //
  134. this->label2->AutoSize = true;
  135. this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  136. static_cast<System::Byte>(0)));
  137. this->label2->Location = System::Drawing::Point(17, 85);
  138. this->label2->Name = L"label2";
  139. this->label2->Size = System::Drawing::Size(106, 24);
  140. this->label2->TabIndex = 5;
  141. this->label2->Text = L"Contraseña";
  142. //
  143. // exit
  144. //
  145. this->exit->BackColor = System::Drawing::SystemColors::ControlLight;
  146. this->exit->DialogResult = System::Windows::Forms::DialogResult::Cancel;
  147. this->exit->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
  148. this->exit->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  149. static_cast<System::Byte>(0)));
  150. this->exit->ForeColor = System::Drawing::SystemColors::ActiveCaptionText;
  151. this->exit->Location = System::Drawing::Point(243, 150);
  152. this->exit->Name = L"exit";
  153. this->exit->Size = System::Drawing::Size(94, 39);
  154. this->exit->TabIndex = 4;
  155. this->exit->Text = L"Salir";
  156. this->exit->UseVisualStyleBackColor = false;
  157. this->exit->Click += gcnew System::EventHandler(this, &MyForm::exit_Click);
  158. //
  159. // MyForm
  160. //
  161. this->AcceptButton = this->login;
  162. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  163. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  164. this->BackColor = System::Drawing::SystemColors::Control;
  165. this->CancelButton = this->exit;
  166. this->ClientSize = System::Drawing::Size(396, 207);
  167. this->Controls->Add(this->exit);
  168. this->Controls->Add(this->label2);
  169. this->Controls->Add(this->label1);
  170. this->Controls->Add(this->ipass);
  171. this->Controls->Add(this->iuser);
  172. this->Controls->Add(this->login);
  173. this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
  174. this->Name = L"MyForm";
  175. this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
  176. this->Text = L"Nombre\?";
  177. this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
  178. this->ResumeLayout(false);
  179. this->PerformLayout();
  180.  
  181. }
  182. #pragma endregion
  183.  
  184. private: System::Void login_Click(System::Object^ sender, System::EventArgs^ e) {
  185.  
  186. String ^ username = iuser->Text;
  187. String ^ password = ipass->Text;
  188.  
  189. using namespace System::Runtime::InteropServices;
  190. const char* str_user = (const char*)(Marshal::StringToHGlobalAnsi(username)).ToPointer();
  191. const char* str_pass = (const char*)(Marshal::StringToHGlobalAnsi(password)).ToPointer();
  192.  
  193. authenticate(str_user , str_pass);
  194. }
  195. private: System::Void exit_Click(System::Object^ sender, System::EventArgs^ e) {
  196. this->Close();
  197. }
  198. private: System::Void iuser_TextChanged(System::Object^ sender, System::EventArgs^ e) {
  199. }
  200. private: System::Void ipass_TextChanged(System::Object^ sender, System::EventArgs^ e) {
  201. }
  202. private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
  203. }
  204. private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
  205. }
  206. };
  207. }
  208.  
  209.  
  210. ///////////////////////// globalvariable.h ///////////////////////////
  211.  
  212. #pragma once
  213. #include <iostream>
  214. #include <fstream>
  215. #include <string>
  216. #include "MainForm.h"
  217. #include "MyForm.h"
  218.  
  219. using namespace std;
  220. using namespace System;
  221. using namespace System::Windows::Forms;
  222.  
  223. [STAThreadAttribute]
  224. bool authenticate(string user,string pass) {
  225. bool success = 0;
  226. ifstream file("authdata.txt");
  227. string fusername, fpassword;
  228.  
  229. if (!file) {
  230. MessageBox::Show("No file");
  231. ofstream file("authdata.txt");
  232. file << "admin,admin,3;";
  233. }
  234.  
  235.  
  236. while (file) {
  237. ws(file);
  238. getline(file, fusername, ','); // use ; as delimiter
  239. getline(file, fpassword, ';');
  240.  
  241. cout << fusername << " = " << user << "\n";
  242. cout << fpassword << " = " << pass << "\n";
  243.  
  244. if (fusername == user & fpassword == pass) {
  245. cout << "logged";
  246. bool success = 1;
  247. //CppWinForm3::MainForm ^ mainform = gcnew CppWinForm3::MainForm();
  248. //mainform->Show();
  249. CppWinForm3::MyForm^ first = gcnew CppWinForm3::MyForm();
  250. first->Close();
  251.  
  252. return success;
  253.  
  254. }
  255. }
  256.  
  257. if (success == 0) {
  258. MessageBox::Show("Usuario o contraseña incorrecta", "Ups...", MessageBoxButtons::OK, MessageBoxIcon::Error);
  259. }
  260. return 0;
  261. }
  262.  
  263. //////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement