Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- using System.Security.Cryptography;
- namespace registration
- {
- public partial class registration_panel : Form
- {
- public registration_panel()
- {
- InitializeComponent();
- }
- private void registration_button_Click(object sender, EventArgs e)
- {
- if (username_box.Text == "" ||
- password_box.Text == "" ||
- repassword_box.Text == "" ||
- email_box.Text == "")
- {
- username_box.Text = "Kérem, töltse ki a mezőket!";
- }
- else
- {
- if (username_box.Text == "Kérem, töltse ki a mezőket!!" ||
- username_box.Text == "A művelet sikeres volt!" ||
- username_box.Text == "A művelet nem elvégezhető!" ||
- username_box.Text == "Már létező név!" ||
- username_box.Text == "Túl rövid/hosszú felhasználónév!" ||
- password_box.Text == "Túl rövid/hosszú a jelszó!" ||
- repassword_box.Text == "Nem egyezik a jelszóval!" ||
- email_box.Text == "Már létező email!" ||
- email_box.Text == "Túl rövid/hosszú e-mail cím!" ||
- email_box.Text == "Helytelen e-mail cím!")
- {
- username_box.Text = "";
- password_box.Text = "";
- repassword_box.Text = "";
- email_box.Text = "";
- }
- else
- {
- string_muvelet vizsgal = new string_muvelet();
- keres keres = new keres();
- hash hash = new hash();
- connection connect = new connection();
- MySqlCommand insert = new MySqlCommand();
- if (keres.username_keres(username_box.Text) && keres.email_keres(email_box.Text))
- {
- if (vizsgal.string_meret(username_box.Text) > 6 && vizsgal.string_meret(username_box.Text) < 32)
- {
- if (vizsgal.string_tartalmaz(email_box.Text, '@'))
- {
- if (vizsgal.string_meret(email_box.Text) > 6 && vizsgal.string_meret(email_box.Text) < 40)
- {
- if (password_box.Text == repassword_box.Text)
- {
- string username = username_box.Text;
- string email = email_box.Text;
- string password = hash.sha_pass_hash(username,password_box.Text);
- if (vizsgal.string_meret(password_box.Text) > 6 && vizsgal.string_meret(password) < 60)
- {
- /*FŐRÉSZ - eleje*/
- int expansion = 2;
- if (check_wotlk.Checked)
- {
- expansion = 2;
- }
- else
- {
- if (check_tbc.Checked)
- {
- expansion = 1;
- }
- else if(check_classic.Checked)
- {
- expansion = 0;
- }
- }
- connect.connection_open_realmd();
- try
- {
- insert.Connection = connect.connection_realmd;
- insert.CommandText = "INSERT INTO account (username,sha_pass_hash,email,expansion) VALUES (?UN,?SP,?EM,?EX)";
- insert.Parameters.Add(new MySqlParameter("UN", username));
- insert.Parameters.Add(new MySqlParameter("SP", password));
- insert.Parameters.Add(new MySqlParameter("EM", email));
- insert.Parameters.Add(new MySqlParameter("EX", expansion));
- insert.ExecuteNonQuery();
- connect.connection_close_realmd();
- username_box.Text = "A művelet sikeres volt!";
- password_box.Text = "";
- repassword_box.Text = "";
- email_box.Text = "";
- }
- catch
- {
- username_box.Text = "A művelet nem elvégezhető!";
- }
- /*FŐRÉSZ - vége*/
- }
- else
- {
- password_box.Text = "Túl rövid/hosszú a jelszó!";
- }
- }
- else
- {
- repassword_box.Text = "Nem egyezik a jelszóval!";
- }
- }
- else
- {
- email_box.Text = "Túl rövid/hosszú e-mail cím!";
- }
- }
- else
- {
- email_box.Text = "Helytelen e-mail cím!";
- }
- }
- else
- {
- username_box.Text = "Túl rövid/hosszú felhasználónév!";
- }
- }
- else
- {
- username_box.Text = "Már létező név!";
- email_box.Text = "Már létező e-mail cím!";
- }
- }
- }
- }
- }
- /* Osztályok */
- public class string_muvelet
- {
- /* Stringekkel kapcsolatos műveletek osztálya */
- /* Metódusai: */
- /* string_meret(string) - Megmondja hogy hány karakterből áll a string */
- /* string_tartalmaz(string, karakter) - Megvizsgálja, hogy tartalmaz-e valamilyen karaktert a string */
- public int string_meret(string str)
- {
- int counter = 0;
- for (int i = 0; i < str.Length; i++)
- {
- char chr = str[i];
- counter++;
- }
- return counter;
- }
- public bool string_tartalmaz(string str, char karakter)
- {
- bool success = false;
- for (int i = 0; i < str.Length; i++)
- {
- char chr = str[i];
- if (chr == karakter)
- {
- success = true;
- break;
- }
- }
- if (success)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- public class hash
- {
- /* Hashelésért felelős osztály */
- /* Metódusai: */
- /* sha_pass_hash(felhasználónév, jelszó) - A felhasználónév és a jelszót egybeolvasztva haseli*/
- public string sha_pass_hash(string user, string pass)
- {
- string password = user.ToUpper() + ":" + pass.ToUpper();
- Encoding enc = Encoding.UTF8;
- byte[] password_bytes = enc.GetBytes(password);
- SHA1CryptoServiceProvider password_hash = new SHA1CryptoServiceProvider();
- password = BitConverter.ToString(password_hash.ComputeHash(password_bytes)).Replace("-", "");
- return password;
- }
- }
- public class keres
- {
- /* Az adatbázisban való keresésért felelős osztály */
- /* Metódusai: */
- /* username_keres(felhasználó) - Megnézi hogy létezik-e már a felhasználó */
- /* email_keres(email) - Megnézi hogy ltéezik-e már az email */
- /* common_keres(mit, honnan, hol, holparaméter) - Az általunk megadott paraméterek alapján bármit megnéz, hogy létezik-e */
- public bool username_keres(string user)
- {
- connection connect = new connection();
- connect.connection_open_realmd();
- MySqlCommand username_keres = new MySqlCommand();
- username_keres.Connection = connect.connection_realmd;
- username_keres.CommandText = "SELECT id FROM account WHERE username=?UN";
- username_keres.Parameters.Add(new MySqlParameter("UN", user));
- MySqlDataReader reader = username_keres.ExecuteReader();
- if (reader.Read())
- {
- connect.connection_close_realmd();
- return false;
- }
- else
- {
- connect.connection_close_realmd();
- return true;
- }
- }
- public bool email_keres(string email)
- {
- connection connect = new connection();
- connect.connection_open_realmd();
- MySqlCommand email_keres = new MySqlCommand();
- email_keres.Connection = connect.connection_realmd;
- email_keres.CommandText = "SELECT id FROM account WHERE username=?EM";
- email_keres.Parameters.Add(new MySqlParameter("EM", email));
- MySqlDataReader reader = email_keres.ExecuteReader();
- if (reader.Read())
- {
- connect.connection_close_realmd();
- return false;
- }
- else
- {
- connect.connection_close_realmd();
- return true;
- }
- }
- public bool common_keres(string mit, string honnan, string hol, string holp)
- {
- connection connect = new connection();
- connect.connection_open_realmd();
- MySqlCommand common_keres = new MySqlCommand();
- common_keres.Connection = connect.connection_realmd;
- common_keres.CommandText = "SELECT ?MI FROM ?HN WHERE ?HH=?HO";
- common_keres.Parameters.Add(new MySqlParameter("MI", mit));
- common_keres.Parameters.Add(new MySqlParameter("HN", honnan));
- common_keres.Parameters.Add(new MySqlParameter("HH", hol));
- common_keres.Parameters.Add(new MySqlParameter("HO", holp));
- MySqlDataReader reader = common_keres.ExecuteReader();
- if (reader.Read())
- {
- connect.connection_close_realmd();
- return false;
- }
- else
- {
- connect.connection_close_realmd();
- return true;
- }
- }
- }
- public class connection
- {
- /* A kapcsolatteremtésért felelős osztály */
- /* Metódusai: */
- /* connection_open_realmd() - Realmd adatbázis megnyitása */
- /* connection_close_realmd() - Realmd adatbázis bezárása*/
- /* connection_open_characters() - Chacaters adatbázis megnyitása */
- /* connection_close_characters() - Characters adatbázis bezárása */
- static bool connection_check_realmd = false;
- static bool connection_check_characters = false;
- static string connection_info_realmd =
- "SERVER=localhost;" + // Szerver elérése
- "DATABASE=realmd;" + // Adatbázis neve
- "UID=root;" + // Felhasználónév
- "PASSWORD=root;"; // Jelszó
- static string connection_info_characters =
- "SERVER=localhost;" + // Szerver elérése
- "DATABASE=characters;" + // Adatbázis neve
- "UID=root;" + // Felhasználónév
- "PASSWORD=root;"; // Jelszó
- public MySqlConnection connection_realmd = new MySqlConnection(connection_info_realmd);
- public MySqlConnection connection_characters = new MySqlConnection(connection_info_characters);
- public void connection_open_realmd()
- {
- if (!connection_check_realmd)
- {
- try
- {
- connection_realmd.Open();
- connection_check_realmd = true;
- }
- catch
- {
- MessageBox.Show("Error #000");
- // Error #000 - Nem tudott kapcsolódni a MySQL adatbázishoz
- }
- }
- }
- public void connection_close_realmd()
- {
- if (connection_check_realmd)
- {
- connection_realmd.Close();
- connection_check_realmd = false;
- }
- }
- public void connection_open_characters()
- {
- if (!connection_check_characters)
- {
- try
- {
- connection_characters.Open();
- connection_check_characters = true;
- }
- catch
- {
- MessageBox.Show("Error #000");
- // Error #000 - Nem tudott kapcsolódni a MySQL adatbázishoz
- }
- }
- }
- public void connection_close_characters()
- {
- if (connection_check_characters)
- {
- connection_characters.Close();
- connection_check_characters = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement