internal static void CreateAccount(string clientId, string accountId, string username, string password, string email) { string passwordSalt = GenerateHashSalt(m_HashSize); string passwordHash = GenerateHash(password + passwordSalt); try { using (MySqlConnection mySqlConnection = MySqlConnector.InitializeMySqlConnection()) { if (MySqlConnector.OpenConnection(mySqlConnection)) { using (MySqlCommand c = new MySqlCommand(m_CreateAccountString, mySqlConnection)) { c.Parameters.Add(new MySqlParameter("?id", accountId)); c.Parameters.Add(new MySqlParameter("?account", username)); c.Parameters.Add(new MySqlParameter("?passHash", passwordHash)); c.Parameters.Add(new MySqlParameter("?passSalt", passwordSalt)); c.Parameters.Add(new MySqlParameter("?email", email)); int i = c.ExecuteNonQuery(); if (i > 0) { if (clientId != string.Empty) { NetworkEventDispatcher.InvokeAccountCreationSuccessEvent (new AccountCreationSuccessArgs(clientId)); } Console.WriteLine("Account Successfully Created For: {0}", username); } else { if (clientId != string.Empty) { NetworkEventDispatcher.InvokeAccountCreationFailedEvent (new AccountCreationFailedArgs(clientId, AccountCreationFailType.Unknown)); } Console.WriteLine("Failed To Create New Account For: {0}", username); } MySqlConnector.CloseConnection(mySqlConnection); } } else { Console.WriteLine("[Error]: Unable To Contact Database During: (CreateAccount)."); } } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
internal static bool?QueryAccountExists(string clientId, string username, string email) { try { using (MySqlConnection mySqlConnection = MySqlConnector.InitializeMySqlConnection()) { if (MySqlConnector.OpenConnection(mySqlConnection)) { using (MySqlCommand c = new MySqlCommand(m_QueryAccountNameExistsString, mySqlConnection)) { c.Parameters.Add(new MySqlParameter("?account", username)); using (MySqlDataReader reader = c.ExecuteReader()) { if (reader.Read()) { if (clientId != string.Empty) { NetworkEventDispatcher. //Notify Client Account Name Exists InvokeAccountCreationFailedEvent (new AccountCreationFailedArgs(clientId, AccountCreationFailType.UsernameExists)); } Console.WriteLine ("Failed To Create New Account For: {0} (Username [{1}] Already Exists)", username, reader["account_name"].ToString()); return(true); } } } using (MySqlCommand c = new MySqlCommand(m_QueryAccountEmailExistsString, mySqlConnection)) { c.Parameters.Add(new MySqlParameter("?email", email)); using (MySqlDataReader reader = c.ExecuteReader()) { if (reader.Read()) { if (clientId != string.Empty) { NetworkEventDispatcher. //Notify Client Email Already In Use InvokeAccountCreationFailedEvent (new AccountCreationFailedArgs(clientId, AccountCreationFailType.EmailExists)); } Console.WriteLine("Failed To Create New Account For: {0} (Email Already Exists)", username); return(true); } } } MySqlConnector.CloseConnection(mySqlConnection); return(false); } return(null); //Unable To Open Database Connection } } catch (Exception e) { Console.WriteLine(e.ToString()); return(null); } }