#pragma once
#include <mysql++.h>
#include <windows.h>
#include <iostream>
#include "md5.h"
namespace wforms {
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 LoginForm
/// </summary>
public ref class LoginForm : public System::Windows::Forms::Form
{
public:
LoginForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~LoginForm()
{
if (components)
{
delete components;
}
}
internal: System::Windows::Forms::Button^ Cancel;
protected:
internal: System::Windows::Forms::Button^ OK;
internal: System::Windows::Forms::TextBox^ PasswordTextBox;
internal: System::Windows::Forms::TextBox^ UsernameTextBox;
internal: System::Windows::Forms::Label^ PasswordLabel;
internal: System::Windows::Forms::Label^ UsernameLabel;
internal: System::Windows::Forms::PictureBox^ LogoPictureBox;
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)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(LoginForm::typeid));
this->Cancel = (gcnew System::Windows::Forms::Button());
this->OK = (gcnew System::Windows::Forms::Button());
this->PasswordTextBox = (gcnew System::Windows::Forms::TextBox());
this->UsernameTextBox = (gcnew System::Windows::Forms::TextBox());
this->PasswordLabel = (gcnew System::Windows::Forms::Label());
this->UsernameLabel = (gcnew System::Windows::Forms::Label());
this->LogoPictureBox = (gcnew System::Windows::Forms::PictureBox());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->LogoPictureBox))->BeginInit();
this->SuspendLayout();
//
// Cancel
//
this->Cancel->DialogResult = System::Windows::Forms::DialogResult::Cancel;
this->Cancel->Location = System::Drawing::Point(313, 190);
this->Cancel->Name = L"Cancel";
this->Cancel->Size = System::Drawing::Size(94, 23);
this->Cancel->TabIndex = 12;
this->Cancel->Text = L"&Cancel";
this->Cancel->Click += gcnew System::EventHandler(this, &LoginForm::Cancel_Click);
//
// OK
//
this->OK->Location = System::Drawing::Point(210, 190);
this->OK->Name = L"OK";
this->OK->Size = System::Drawing::Size(94, 23);
this->OK->TabIndex = 11;
this->OK->Text = L"&OK";
this->OK->Click += gcnew System::EventHandler(this, &LoginForm::OK_Click);
//
// PasswordTextBox
//
this->PasswordTextBox->Location = System::Drawing::Point(187, 130);
this->PasswordTextBox->Name = L"PasswordTextBox";
this->PasswordTextBox->PasswordChar = '*';
this->PasswordTextBox->Size = System::Drawing::Size(220, 20);
this->PasswordTextBox->TabIndex = 10;
//
// UsernameTextBox
//
this->UsernameTextBox->Location = System::Drawing::Point(187, 73);
this->UsernameTextBox->Name = L"UsernameTextBox";
this->UsernameTextBox->Size = System::Drawing::Size(220, 20);
this->UsernameTextBox->TabIndex = 8;
//
// PasswordLabel
//
this->PasswordLabel->Location = System::Drawing::Point(185, 110);
this->PasswordLabel->Name = L"PasswordLabel";
this->PasswordLabel->Size = System::Drawing::Size(220, 23);
this->PasswordLabel->TabIndex = 9;
this->PasswordLabel->Text = L"&Password";
this->PasswordLabel->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
//
// UsernameLabel
//
this->UsernameLabel->Location = System::Drawing::Point(185, 53);
this->UsernameLabel->Name = L"UsernameLabel";
this->UsernameLabel->Size = System::Drawing::Size(220, 23);
this->UsernameLabel->TabIndex = 6;
this->UsernameLabel->Text = L"&User name";
this->UsernameLabel->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
//
// LogoPictureBox
//
this->LogoPictureBox->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"LogoPictureBox.Image")));
this->LogoPictureBox->Location = System::Drawing::Point(13, 69);
this->LogoPictureBox->Name = L"LogoPictureBox";
this->LogoPictureBox->Size = System::Drawing::Size(168, 81);
this->LogoPictureBox->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
this->LogoPictureBox->TabIndex = 7;
this->LogoPictureBox->TabStop = false;
//
// LoginForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(421, 266);
this->Controls->Add(this->Cancel);
this->Controls->Add(this->OK);
this->Controls->Add(this->PasswordTextBox);
this->Controls->Add(this->UsernameTextBox);
this->Controls->Add(this->PasswordLabel);
this->Controls->Add(this->UsernameLabel);
this->Controls->Add(this->LogoPictureBox);
this->Name = L"LoginForm";
this->Text = L"LoginForm";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->LogoPictureBox))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
// Takes a string in the .NET platform's native Unicode format and
// copies it to the given C string buffer in UTF-8 encoding.
Void ToUTF8(char* pcOut, int nOutLen, String^ sIn)
{
array<Byte>^ bytes = System::Text::Encoding::UTF8->GetBytes(sIn);
nOutLen = Math::Min(nOutLen - 1, bytes->Length);
System::Runtime::InteropServices::Marshal::Copy(bytes, 0,
IntPtr(pcOut), nOutLen);
pcOut[nOutLen] = '\0';
}
private: System::Void OK_Click(System::Object^ sender, System::EventArgs^ e)
{
mysqlpp::Connection con(false);
if (!con.connect("db", "server", "thewge", "password"))
{
Application::Exit();
}
// Retrieve a subset of the sample stock table set up by resetdb
mysqlpp::Query query = con.query();
//query << "SELECT username, password FROM wge_db_user WHERE username = 'da*beast'";
const int kInputBufSize = 100;
char acsUserName[kInputBufSize];
char acsPassword[kInputBufSize];
ToUTF8(acsUserName, kInputBufSize, UsernameTextBox->Text);
ToUTF8(acsPassword, kInputBufSize, PasswordTextBox->Text);
//md5(acsPassword);
query << "SELECT username, password FROM wge_db_user WHERE username = '" << acsUserName << "' and password = '" << md5(acsPassword) << "'";
mysqlpp::StoreQueryResult res = query.store();
mysqlpp::Row row;
if (res.num_rows() > 0)
{
//goodlogin - show new form and hide this form
}
else
{
//badlogin
}
mysqlpp::Connection::thread_end();
return;
}
private: System::Void Cancel_Click(System::Object^ sender, System::EventArgs^ e)
{
Application::Exit();
}
};
}
Bookmarks