Advertisement
Guest User

Untitled

a guest
Sep 18th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.93 KB | None | 0 0
  1. #pragma once
  2. #include <array>
  3. #include <string>
  4. #include <iostream>
  5. #include <cstring>
  6. #include "MyForm2.h"
  7.  
  8. namespace loginpp {
  9.  
  10.     using namespace System;
  11.     using namespace System::ComponentModel;
  12.     using namespace System::Collections;
  13.     using namespace System::Windows::Forms;
  14.     using namespace System::Data;
  15.     using namespace System::Drawing;
  16.  
  17.     /// <summary>
  18.     /// Summary for MyForm
  19.     /// </summary>
  20.     public ref class MyForm : public System::Windows::Forms::Form
  21.     {
  22.         int attempt = 0;
  23.     public:
  24.         MyForm(void)
  25.         {
  26.             InitializeComponent();
  27.             //
  28.             //TODO: Add the constructor code here
  29.             //
  30.         }
  31.  
  32.     protected:
  33.         /// <summary>
  34.         /// Clean up any resources being used.
  35.         /// </summary>
  36.         ~MyForm()
  37.         {
  38.             if (components)
  39.             {
  40.                 delete components;
  41.             }
  42.         }
  43.     private: System::Windows::Forms::Label^  label1;
  44.     protected:
  45.     private: System::Windows::Forms::Button^  button1;
  46.     private: System::Windows::Forms::TextBox^  textBoxLogin;
  47.     private: System::Windows::Forms::Label^  label2;
  48.     private: System::Windows::Forms::TextBox^  textBoxPassword;
  49.  
  50.     private:
  51.         /// <summary>
  52.         /// Required designer variable.
  53.         /// </summary>
  54.         System::ComponentModel::Container ^components;
  55.  
  56. #pragma region Windows Form Designer generated code
  57.         /// <summary>
  58.         /// Required method for Designer support - do not modify
  59.         /// the contents of this method with the code editor.
  60.         /// </summary>
  61.         void InitializeComponent(void)
  62.         {
  63.             this->label1 = (gcnew System::Windows::Forms::Label());
  64.             this->button1 = (gcnew System::Windows::Forms::Button());
  65.             this->textBoxLogin = (gcnew System::Windows::Forms::TextBox());
  66.             this->label2 = (gcnew System::Windows::Forms::Label());
  67.             this->textBoxPassword = (gcnew System::Windows::Forms::TextBox());
  68.             this->SuspendLayout();
  69.             //
  70.             // label1
  71.             //
  72.             this->label1->AutoSize = true;
  73.             this->label1->Location = System::Drawing::Point(46, 53);
  74.             this->label1->Name = L"label1";
  75.             this->label1->Size = System::Drawing::Size(58, 13);
  76.             this->label1->TabIndex = 0;
  77.             this->label1->Text = L"Username:";
  78.             //
  79.             // button1
  80.             //
  81.             this->button1->Location = System::Drawing::Point(49, 122);
  82.             this->button1->Name = L"button1";
  83.             this->button1->Size = System::Drawing::Size(161, 23);
  84.             this->button1->TabIndex = 1;
  85.             this->button1->Text = L"Login";
  86.             this->button1->UseVisualStyleBackColor = true;
  87.             this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
  88.             //
  89.             // textBoxLogin
  90.             //
  91.             this->textBoxLogin->Location = System::Drawing::Point(110, 50);
  92.             this->textBoxLogin->Name = L"textBoxLogin";
  93.             this->textBoxLogin->Size = System::Drawing::Size(100, 20);
  94.             this->textBoxLogin->TabIndex = 2;
  95.             //
  96.             // label2
  97.             //
  98.             this->label2->AutoSize = true;
  99.             this->label2->Location = System::Drawing::Point(46, 88);
  100.             this->label2->Name = L"label2";
  101.             this->label2->Size = System::Drawing::Size(56, 13);
  102.             this->label2->TabIndex = 3;
  103.             this->label2->Text = L"Password:";
  104.             //
  105.             // textBoxPassword
  106.             //
  107.             this->textBoxPassword->Location = System::Drawing::Point(110, 85);
  108.             this->textBoxPassword->Name = L"textBoxPassword";
  109.             this->textBoxPassword->Size = System::Drawing::Size(100, 20);
  110.             this->textBoxPassword->TabIndex = 4;
  111.             //
  112.             // MyForm
  113.             //
  114.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  115.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  116.             this->ClientSize = System::Drawing::Size(252, 178);
  117.             this->Controls->Add(this->textBoxPassword);
  118.             this->Controls->Add(this->label2);
  119.             this->Controls->Add(this->textBoxLogin);
  120.             this->Controls->Add(this->button1);
  121.             this->Controls->Add(this->label1);
  122.             this->Name = L"MyForm";
  123.             this->ShowIcon = false;
  124.             this->Text = L"Login";
  125.             this->ResumeLayout(false);
  126.             this->PerformLayout();
  127.  
  128.         }
  129. #pragma endregion
  130.     private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
  131.     {
  132.         std::string StringLogin[3] {"admin", "user", "user2"};
  133.         std::string StringPassword[3] {"123123", "123321", "u123123"};
  134.  
  135.         for (int i = 0; i < 3; i++)
  136.         {
  137.             String^ checkName = gcnew String(StringLogin[i].c_str());
  138.  
  139.             if (textBoxLogin->Text == checkName)
  140.             {
  141.                 String^ checkPassword = gcnew String(StringPassword[i].c_str());
  142.                 if (textBoxPassword->Text == checkPassword)
  143.                 {
  144.                     if (textBoxLogin->Text == gcnew String(StringLogin[0].c_str()) && textBoxPassword->Text == gcnew String(StringPassword[0].c_str()))
  145.                     {//Admin logged
  146.                         this->Hide();
  147.                         MyForm2^ f2 = gcnew MyForm2();
  148.                         for (int i = 0; i < 3; ++i)
  149.                         {
  150.                             f2->textBox1->Text += gcnew String(StringLogin[i].c_str()) + "\t\t" + gcnew String(StringPassword[i].c_str()) + Environment::NewLine;
  151.                         }
  152.                         f2->ShowDialog();
  153.                     }// User logged
  154.                     MessageBox::Show("Login successfull", "You are logged in");
  155.                 }
  156.             }
  157.             else
  158.             {
  159.                 attempt++;
  160.                 if (attempt >= 9)
  161.                 {
  162.                     Application::Exit();
  163.                 }
  164.             }
  165.         }
  166.     }
  167. };
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement