private void login_btn_Click(object sender, EventArgs e) { if (!(File.Exists(path))) { MessageBox.Show("Elöbb regisztrálj!"); login_panel.Hide(); } else { DirectoryInfo dcc = new DirectoryInfo(path); dcc.Attributes = FileAttributes.Normal; string[] user_data_i = File.ReadAllLines(path); log_namenome = Convert.ToString(login_username.Text); log_password = Convert.ToString(login_pasword.Text); SHA1 sha1 = new SHA1CryptoServiceProvider(); string texty = log_password; byte[] hashedDatalog = sha1.ComputeHash(Encoding.Unicode.GetBytes(texty)); StringBuilder stringBuilderL = new StringBuilder(); string[] pswd_hsh = new string[200]; int ei = 0; foreach (byte c in hashedDatalog) { stringBuilderL.Append(String.Format("{0,2:X2}", c)); pswd_hsh[ei] = Convert.ToString(c); ei++; } string sha = string.Join("", pswd_hsh); server = "remotemysql.com"; database = "iVn5Bs3UhN"; uid = "iVn5Bs3UhN"; password = "******"; string connectionString; connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";"; connection = new MySqlConnection(connectionString); connection.Open(); string log_query = "SELECT `username`, `password` FROM `Mr_Lucky`"; MySqlCommand cmd = new MySqlCommand(log_query, connection); MySqlDataReader dataReader = cmd.ExecuteReader(); List <string> sql_uname = new List <string>(); List <string> sql_password = new List <string>(); while (dataReader.Read()) { if (dataReader[0].ToString() == log_namenome && dataReader[1].ToString() == log_password) { MessageBox.Show("Sikeres bejelentkezés", "Engedélyezve", MessageBoxButtons.OK, MessageBoxIcon.Information); log.Add("Sikeres bejelentkezés az adatbázisba " + log_namenome + " néven " + DateTime.Now + " kor"); File.WriteAllLines(log_path, log); dcc.Attributes = FileAttributes.Hidden; loggedin = 1; dataReader.Close(); connection.Close(); lvlchoose lvlchoose = new lvlchoose(); this.Hide(); lvlchoose.Show(); break; } else { loggedin = 2; } } if (loggedin == 2) { MessageBox.Show("Helytelen felhasználónév/jelszó", "Nem engedélyezett belépés", MessageBoxButtons.OK, MessageBoxIcon.Error); login_username.Clear(); login_pasword.Clear(); } /*if (!(user_data_i[0] == log_namenome)) * { * MessageBox.Show("Helytelen felhasználónév", "Hiba...", MessageBoxButtons.OK, MessageBoxIcon.Error); * login_username.Clear(); * } * else if (!(user_data_i[1] == sha)) * { * MessageBox.Show("Helytelen jelszó", "Hiba...", MessageBoxButtons.OK, MessageBoxIcon.Error); * login_pasword.Clear(); * } * else * if (!(sql_uname.Contains(log_namenome))) * { * MessageBox.Show("Nincs ilyen felhasználó az adatbázisban", "Hiba...", MessageBoxButtons.OK, MessageBoxIcon.Error); * login_username.Clear(); * } * else if (!(sql_password.Contains(log_password))) * { * MessageBox.Show("Nincs ilyen jelszó az adatbázisban", "Hiba...", MessageBoxButtons.OK, MessageBoxIcon.Error); * login_pasword.Clear(); * } * else * { * MessageBox.Show("Sikeres bejelentkezés", "Engedélyezve", MessageBoxButtons.OK, MessageBoxIcon.Information); * log.Add("Sikeres bejelentkezés " + log_namenome + " néven " + DateTime.Now + " kor"); * File.WriteAllLines(log_path, log); * } * connection.Close(); * dcc.Attributes = FileAttributes.Hidden;*/ } }
private void login_btn_Click(object sender, EventArgs e) { if (!(File.Exists(path))) { MessageBox.Show("Elöbb regisztrálj!"); login_panel.Hide(); } else { DirectoryInfo dcc = new DirectoryInfo(path); dcc.Attributes = FileAttributes.Normal; string[] user_data_i = File.ReadAllLines(path); log_namenome = Convert.ToString(login_username.Text); log_password = Convert.ToString(login_pasword.Text); SHA1 sha1 = new SHA1CryptoServiceProvider(); string texty = log_password; byte[] hashedDatalog = sha1.ComputeHash(Encoding.Unicode.GetBytes(texty)); StringBuilder stringBuilderL = new StringBuilder(); string[] pswd_hsh = new string[200]; int ei = 0; foreach (byte c in hashedDatalog) { stringBuilderL.Append(String.Format("{0,2:X2}", c)); pswd_hsh[ei] = Convert.ToString(c); ei++; } string sha = string.Join("", pswd_hsh); server = "remotemysql.com"; database = "iVn5Bs3UhN"; uid = "iVn5Bs3UhN"; password = "******"; string connectionString; connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";"; connection = new MySqlConnection(connectionString); try { connection.Open(); log_query = "SELECT `computer_name`,`username`,`password`,`creation_date`,`last_login` FROM `Mr_Lucky`"; } catch (MySqlException ex) { MessageBox.Show(ex.Message); Application.Exit(); } MySqlCommand cmd = new MySqlCommand(log_query, connection); MySqlDataReader dataReader = cmd.ExecuteReader(); List <string> sql_uname = new List <string>(); List <string> sql_password = new List <string>(); while (dataReader.Read()) { if (dataReader[1].ToString() == log_namenome && dataReader[2].ToString() == log_password) { if (dataReader[1].ToString() == log_namenome && dataReader[1].ToString() != user_data_i[0]) { DialogResult dialogresult = MessageBox.Show("Ez felhasználó nem létezik ezen a számítógépen. Kívánja importálni az adatokat?", "Félreértésbe ütköztem... HJELP", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (dialogresult == DialogResult.Yes) { SHA1 sha2 = new SHA1CryptoServiceProvider(); string texty2 = dataReader[2].ToString(); byte[] hashedDatalog2 = sha1.ComputeHash(Encoding.Unicode.GetBytes(texty2)); StringBuilder stringBuilderL2 = new StringBuilder(); string[] pswd_hsh2 = new string[200]; int ei2 = 0; foreach (byte c in hashedDatalog) { stringBuilderL.Append(String.Format("{0,2:X2}", c)); pswd_hsh2[ei2] = Convert.ToString(c); ei2++; } string shae = string.Join("", pswd_hsh2); log.Add("Sikeres adatimportálás és jelszókódolás " + DateTime.Now + " kor"); string[] user_data_EIO = { dataReader[1].ToString(), shae }; File.WriteAllLines(path, user_data_EIO); log.Add("Sikeres adatexportálás " + DateTime.Now + " kor"); MessageBox.Show("Kérlek jelentkezz be ismét."); File.WriteAllLines(log_path, log); login_username.Clear(); login_pasword.Clear(); dcc.Attributes = FileAttributes.Hidden; } loggedin = 3; break; } else { last_login = "******" + DateTime.Now.ToString() + "' WHERE `username` ='" + log_namenome + "'"; MessageBox.Show("Sikeres bejelentkezés", "Engedélyezve", MessageBoxButtons.OK, MessageBoxIcon.Information); log.Add("Sikeres bejelentkezés az adatbázisba " + log_namenome + " néven " + DateTime.Now + " kor"); loggedin = 0; dcc.Attributes = FileAttributes.Hidden; break; } } else { loggedin = 2; } } if (loggedin == 2) { MessageBox.Show("Helytelen felhasználónév/jelszó", "Nem engedélyezett belépés", MessageBoxButtons.OK, MessageBoxIcon.Error); login_username.Clear(); login_pasword.Clear(); loggedin = 0; dcc.Attributes = FileAttributes.Hidden; } else if (loggedin == 0) { connection.Close(); connection.Open(); MySqlCommand last_login_cmd = new MySqlCommand(last_login, connection); last_login_cmd.ExecuteNonQuery(); connection.Close(); File.WriteAllLines(log_path, log); dcc.Attributes = FileAttributes.Hidden; loggedin = 1; dataReader.Close(); connection.Close(); lvlchoose lvlchoose = new lvlchoose(); this.Hide(); lvlchoose.Show(); } /*if (!(user_data_i[0] == log_namenome)) * { * MessageBox.Show("Helytelen felhasználónév", "Hiba...", MessageBoxButtons.OK, MessageBoxIcon.Error); * login_username.Clear(); * } * else if (!(user_data_i[1] == sha)) * { * MessageBox.Show("Helytelen jelszó", "Hiba...", MessageBoxButtons.OK, MessageBoxIcon.Error); * login_pasword.Clear(); * } * else * if (!(sql_uname.Contains(log_namenome))) * { * MessageBox.Show("Nincs ilyen felhasználó az adatbázisban", "Hiba...", MessageBoxButtons.OK, MessageBoxIcon.Error); * login_username.Clear(); * } * else if (!(sql_password.Contains(log_password))) * { * MessageBox.Show("Nincs ilyen jelszó az adatbázisban", "Hiba...", MessageBoxButtons.OK, MessageBoxIcon.Error); * login_pasword.Clear(); * } * else * { * MessageBox.Show("Sikeres bejelentkezés", "Engedélyezve", MessageBoxButtons.OK, MessageBoxIcon.Information); * log.Add("Sikeres bejelentkezés " + log_namenome + " néven " + DateTime.Now + " kor"); * File.WriteAllLines(log_path, log); * } * connection.Close(); * dcc.Attributes = FileAttributes.Hidden;*/ } }