private void try_register() { try { if (txt_chk.is_empty(username_input.Text)) { throw new Exception("Sisestage kasutajanimi!"); } if (txt_chk.is_empty(password_input.Text)) { throw new Exception("Sisestage parool!"); } if (txt_chk.is_empty(password_repeat_input.Text)) { throw new Exception("Sisestage kordus parool!"); } if (txt_chk.is_empty(email_input.Text)) { throw new Exception("Sisestage email!"); } if (txt_chk.is_empty(steamid_input.Text)) { throw new Exception("Valige menüüst enda steamid!"); } if (password_repeat_input.Text != password_input.Text) { throw new Exception("Sisestatud paroolid ei klapi!"); } if (!txt_chk.is_text_aZ09(username_input.Text)) { throw new Exception("Kasutajanimi tohib sisaldada ainult\n tähti a-Z ja numbreid 0-9!"); } if (!txt_chk.is_email(email_input.Text)) { throw new Exception("Emaili formaat on ebakorrektne!"); } UnicodeEncoding UE = new UnicodeEncoding(); byte[] message = UE.GetBytes(password_input.Text); SHA512Managed hashString = new SHA512Managed(); string sha512_password = ""; byte[] hashValue = hashString.ComputeHash(message); foreach (byte x in hashValue) { sha512_password += String.Format("{0:x2}", x); } network udpcon = new network(); if (udpcon.connect_to_server()) { List <string> reg_packet = new List <string>(); reg_packet.Add(username_input.Text); reg_packet.Add(username_input.Text.ToLower()); reg_packet.Add(sha512_password); reg_packet.Add(email_input.Text); reg_packet.Add(steamid_input.Text); byte[] register_response = udpcon.send_and_recieve(0x18, reg_packet); if (register_response[0] == 0xFF) { // successful register c_msgbox.show_msg(false, "Registreerimine õnnestus!"); this.Close(); } else { // failed to register switch (register_response[1]) { case 0x01: throw new Exception("Server ei suutnud registreerimist käsitleda!"); case 0x02: throw new Exception("Selline kasutajanimi juba eksisteerib!"); case 0x03: throw new Exception("Selline e-mail juba eksisteerib!"); case 0x04: throw new Exception("Selline steamid juba eksisteerib!"); case 0x06: throw new Exception("Serveriga ühenduse loomine ebaõnnestus!"); } } } else { c_msgbox.show_msg(true, "Serveriga ühenduse loomine ebaõnnestus!"); } } catch (Exception ex) { c_msgbox.show_msg(false, ex.Message); } }
private void try_login() { try { if (username_input.Text == "") { throw new Exception("Sisesta kasutajanimi"); } if (password_input.Text == "") { throw new Exception("Sisesta parool"); } network udpcon = new network(); if (udpcon.connect_to_server()) { // Get sha512 password string sha512_password = ""; if (Properties.Settings.Default.remember_me) { sha512_password = Properties.Settings.Default.sha512_pw; } else { UnicodeEncoding UE = new UnicodeEncoding(); byte[] message = UE.GetBytes(password_input.Text); SHA512Managed hashString = new SHA512Managed(); byte[] hashValue = hashString.ComputeHash(message); foreach (byte x in hashValue) { sha512_password += String.Format("{0:x2}", x); } } // Let's start building the packet List <string> login_packet = new List <string>(); string version = Properties.Settings.Default.version.ToString(); //Clipboard.SetText(sha512_password); if (version.Contains(",")) { version = version.Replace(',', '.'); } login_packet.Add(username_input.Text.ToLower()); login_packet.Add(sha512_password); login_packet.Add(version); login_packet.Add(get_hw_id()); // Send login packet and recieve response byte[] login_response = udpcon.send_and_recieve(0x02, login_packet); if (login_response[0] == 0xFA) { // we have failed login attempt switch (login_response[1]) { case 0x01: throw new Exception("Tundmatu veateade!"); case 0x02: throw new Exception("Sinu kliendi versioon on liiga vana!"); case 0x03: throw new Exception("Vale kasutajanimi või parool!"); case 0x04: throw new Exception("Kasutaja on juba sisse loginud. Juhul kui Sinu ühendus aegus, oota 2min!"); case 0x05: List <string> ban_info = udpcon.extract_data(login_response); throw new Exception("Sa oled banned.\nPõhjus: " + ban_info[0] + "\nKestab kuni: " + ban_info[1]); case 0x06: throw new Exception("Serveriga ühenduse loomine ebaõnnestus!"); } } if (login_response[0] == 0xFF) { // Login was successful List <string> recieved_data = udpcon.extract_data(login_response); steamid = recieved_data[0]; string password = recieved_data[1]; s_hash = long.Parse(recieved_data[2]); if (password != sha512_password) { List <string> abuse_data = new List <string>(); abuse_data.Add("Passwords do not match at user-side after getting 'ok'"); //main_client.send_data(0x16, abuseData); } else { if (remember_me.Checked) { string keyName = @"HKEY_CURRENT_USER\SOFTWARE\everest\Gather"; Registry.SetValue(keyName, "username", username_input.Text); Registry.SetValue(keyName, "password", sha512_password); Registry.SetValue(keyName, "remember_me", true); } else { string keyName = @"HKEY_CURRENT_USER\SOFTWARE\everest\Gather"; Registry.SetValue(keyName, "username", ""); Registry.SetValue(keyName, "password", ""); Registry.SetValue(keyName, "remember_me", false); } // initialize new window and give refrence to connection and this form main_hub_scr main_window = new main_hub_scr(this, udpcon); main_window.Show(); this.Hide(); //throw new Exception("LOGIN OK"); } } //c_msgbox.show_msg(false, "See funktsioon ei ole valmis veel!\nSinu hw_id: " + get_hw_id()); } else { c_msgbox.show_msg(true, "Serveriga ühenduse loomine ebaõnnestus!"); } } catch (Exception ex) { c_msgbox.show_msg(true, ex.Message); } }