Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////// MyForm.h ///////////////////////////////
- #pragma once
- #include "globalvariable.h"
- #include "MainForm.h"
- namespace CppWinForm3 {
- 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>
- /// Summary for MyForm
- /// </summary>
- public ref class MyForm : public System::Windows::Forms::Form
- {
- public:
- MyForm(void)
- {
- InitializeComponent();
- //
- //TODO: Add the constructor code here
- //
- }
- protected:
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- ~MyForm()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::Button^ login;
- private: System::Windows::Forms::TextBox^ iuser;
- private: System::Windows::Forms::TextBox^ ipass;
- protected:
- protected:
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::Label^ label2;
- private: System::Windows::Forms::Button^ exit;
- private:
- /// <summary>
- /// Required designer variable.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- void InitializeComponent(void)
- {
- this->login = (gcnew System::Windows::Forms::Button());
- this->iuser = (gcnew System::Windows::Forms::TextBox());
- this->ipass = (gcnew System::Windows::Forms::TextBox());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->label2 = (gcnew System::Windows::Forms::Label());
- this->exit = (gcnew System::Windows::Forms::Button());
- this->SuspendLayout();
- //
- // login
- //
- this->login->BackColor = System::Drawing::SystemColors::ControlLight;
- this->login->FlatAppearance->BorderSize = 0;
- this->login->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
- this->login->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->login->ForeColor = System::Drawing::SystemColors::ActiveCaptionText;
- this->login->Location = System::Drawing::Point(89, 150);
- this->login->Name = L"login";
- this->login->Size = System::Drawing::Size(94, 36);
- this->login->TabIndex = 3;
- this->login->Text = L"Entrar";
- this->login->UseVisualStyleBackColor = false;
- this->login->Click += gcnew System::EventHandler(this, &MyForm::login_Click);
- //
- // iuser
- //
- this->iuser->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
- this->iuser->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->iuser->Location = System::Drawing::Point(148, 40);
- this->iuser->Name = L"iuser";
- this->iuser->Size = System::Drawing::Size(206, 29);
- this->iuser->TabIndex = 1;
- this->iuser->TextChanged += gcnew System::EventHandler(this, &MyForm::iuser_TextChanged);
- //
- // ipass
- //
- this->ipass->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
- this->ipass->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->ipass->Location = System::Drawing::Point(148, 84);
- this->ipass->Name = L"ipass";
- this->ipass->PasswordChar = '*';
- this->ipass->Size = System::Drawing::Size(206, 29);
- this->ipass->TabIndex = 2;
- this->ipass->TextChanged += gcnew System::EventHandler(this, &MyForm::ipass_TextChanged);
- //
- // label1
- //
- this->label1->AccessibleDescription = L"";
- this->label1->AutoSize = true;
- this->label1->BackColor = System::Drawing::SystemColors::Control;
- this->label1->FlatStyle = System::Windows::Forms::FlatStyle::Popup;
- this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->label1->Location = System::Drawing::Point(33, 43);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(74, 24);
- this->label1->TabIndex = 4;
- this->label1->Text = L"Usuario";
- this->label1->Click += gcnew System::EventHandler(this, &MyForm::label1_Click);
- //
- // label2
- //
- this->label2->AutoSize = true;
- this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->label2->Location = System::Drawing::Point(17, 85);
- this->label2->Name = L"label2";
- this->label2->Size = System::Drawing::Size(106, 24);
- this->label2->TabIndex = 5;
- this->label2->Text = L"Contraseña";
- //
- // exit
- //
- this->exit->BackColor = System::Drawing::SystemColors::ControlLight;
- this->exit->DialogResult = System::Windows::Forms::DialogResult::Cancel;
- this->exit->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
- this->exit->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->exit->ForeColor = System::Drawing::SystemColors::ActiveCaptionText;
- this->exit->Location = System::Drawing::Point(243, 150);
- this->exit->Name = L"exit";
- this->exit->Size = System::Drawing::Size(94, 39);
- this->exit->TabIndex = 4;
- this->exit->Text = L"Salir";
- this->exit->UseVisualStyleBackColor = false;
- this->exit->Click += gcnew System::EventHandler(this, &MyForm::exit_Click);
- //
- // MyForm
- //
- this->AcceptButton = this->login;
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->BackColor = System::Drawing::SystemColors::Control;
- this->CancelButton = this->exit;
- this->ClientSize = System::Drawing::Size(396, 207);
- this->Controls->Add(this->exit);
- this->Controls->Add(this->label2);
- this->Controls->Add(this->label1);
- this->Controls->Add(this->ipass);
- this->Controls->Add(this->iuser);
- this->Controls->Add(this->login);
- this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
- this->Name = L"MyForm";
- this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
- this->Text = L"Nombre\?";
- this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- private: System::Void login_Click(System::Object^ sender, System::EventArgs^ e) {
- String ^ username = iuser->Text;
- String ^ password = ipass->Text;
- using namespace System::Runtime::InteropServices;
- const char* str_user = (const char*)(Marshal::StringToHGlobalAnsi(username)).ToPointer();
- const char* str_pass = (const char*)(Marshal::StringToHGlobalAnsi(password)).ToPointer();
- authenticate(str_user , str_pass);
- }
- private: System::Void exit_Click(System::Object^ sender, System::EventArgs^ e) {
- this->Close();
- }
- private: System::Void iuser_TextChanged(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void ipass_TextChanged(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
- }
- };
- }
- ///////////////////////// globalvariable.h ///////////////////////////
- #pragma once
- #include <iostream>
- #include <fstream>
- #include <string>
- #include "MainForm.h"
- #include "MyForm.h"
- using namespace std;
- using namespace System;
- using namespace System::Windows::Forms;
- [STAThreadAttribute]
- bool authenticate(string user,string pass) {
- bool success = 0;
- ifstream file("authdata.txt");
- string fusername, fpassword;
- if (!file) {
- MessageBox::Show("No file");
- ofstream file("authdata.txt");
- file << "admin,admin,3;";
- }
- while (file) {
- ws(file);
- getline(file, fusername, ','); // use ; as delimiter
- getline(file, fpassword, ';');
- cout << fusername << " = " << user << "\n";
- cout << fpassword << " = " << pass << "\n";
- if (fusername == user & fpassword == pass) {
- cout << "logged";
- bool success = 1;
- //CppWinForm3::MainForm ^ mainform = gcnew CppWinForm3::MainForm();
- //mainform->Show();
- CppWinForm3::MyForm^ first = gcnew CppWinForm3::MyForm();
- first->Close();
- return success;
- }
- }
- if (success == 0) {
- MessageBox::Show("Usuario o contraseña incorrecta", "Ups...", MessageBoxButtons::OK, MessageBoxIcon::Error);
- }
- return 0;
- }
- //////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement