Guest User

Untitled

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