/// <summary> /// Logins the user hashed. /// </summary> /// <returns>The user hashed.</returns> /// <param name="userNick">User nick.</param> /// <param name="userPassword">User hashed password.</param> public static ServerPacketUserLogin LoginUserHashed(String userNick, String userPassword) { //new user login packet ClientPacketUserLogin clientPacketUserLogin = new ClientPacketUserLogin(userNick, userPassword); //send login to server ServerPacketUserLogin serverPacketUserLogin = TCPClient.SendPacket(clientPacketUserLogin) as ServerPacketUserLogin; //if no answer if (serverPacketUserLogin == null) { return(new ServerPacketUserLogin(NetworkError.SERVER_UNAVAILABLE, null, false, null)); } return(serverPacketUserLogin); }
/// <summary> /// Auth the specified connectionProfile. /// </summary> /// <param name="connectionProfile">Connection profile.</param> public void Auth(ConnectionProfile connectionProfile) { //send login packet ServerPacketUserLogin serverPacketUserLogin = ServerHelper.LoginUserHashed(connectionProfile.UserName, connectionProfile.UserPassword); //if login success if (serverPacketUserLogin.NetworkError == NetworkError.NONE) { //set actual user infos Application.ActualUser = serverPacketUserLogin.UserProfile; Application.UserPassword = tfPasswordField.Text; if (serverPacketUserLogin.UserAccountActivate) { if (serverPacketUserLogin.UserDAuthPrivateKey != null) { Application.ActualUserPrivateKey = serverPacketUserLogin.UserDAuthPrivateKey; PerformSegue("DAuthLoginSegue", this); return; } //load user pets Application.PetManager.LoadUserPetList(serverPacketUserLogin.UserProfile); //instantiate main view controller UIStoryboard mainBoard = UIStoryboard.FromName("Main", null); MainTabBarController mainTabBarController = mainBoard.InstantiateViewController("MainTabBarController") as MainTabBarController; PresentViewController(mainTabBarController, true, null); } else { PerformSegue("ConnectConfirmAccountSegue", this); } return; } //chose right error message String messageError = string.Empty; switch (serverPacketUserLogin.NetworkError) { case NetworkError.GLOBAL_UNKNOWN: goto default; case NetworkError.SQL_USER_UNKNOWN: messageError = "Utilisateur ou mot de passe incorect"; break; case NetworkError.SERVER_UNAVAILABLE: messageError = MSGBank.ERROR_NO_SERVER; break; default: messageError = MSGBank.ERROR_UNKNOWN; break; } BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, messageError, 5); //ßMessageBox.ShowOK(MSGBank.ERROR_TITLE, messageError, this); }
public override Packet OnPacketReceive(Packet receivedPacket) { ClientPacketUserLogin clientPacketUserLogin = receivedPacket as ClientPacketUserLogin; ConsoleHelper.Write("Receive - ClientPacketUserLogin"); String userNick = clientPacketUserLogin.UserName.ToSQL(); String userPassword = clientPacketUserLogin.UserPassword.ToSQL(); //login user db command MySqlCommand loginUserCommand = new MySqlCommand(); loginUserCommand.Connection = Program.mySQLManager.MySQLConnection.MysqlConnection; loginUserCommand.CommandText = $"SELECT * FROM `T_User` WHERE userNick='{userNick}' AND userPassword='******'"; MySqlDataReader mysqlDataReader = null; ServerPacketUserLogin serverPacketUserLogin; Boolean userAccountActive = false; try { mysqlDataReader = loginUserCommand.ExecuteReader(); PLFUser user = null; //open reader while (mysqlDataReader.Read()) { user = new PLFUser(mysqlDataReader.GetInt32(0), mysqlDataReader.GetString(2), mysqlDataReader.GetString(3), mysqlDataReader.GetString(4), mysqlDataReader.GetString(5)); userAccountActive = mysqlDataReader.GetBoolean(6); } mysqlDataReader.Close(); if (user != null) { //login user db command MySqlCommand getUserDAuthKeyCommand = new MySqlCommand(); getUserDAuthKeyCommand.Connection = Program.mySQLManager.MySQLConnection.MysqlConnection; getUserDAuthKeyCommand.CommandText = $"SELECT * FROM `T_DoubleAuth` WHERE `daUserID`='{user.ID}'"; mysqlDataReader = getUserDAuthKeyCommand.ExecuteReader(); String userKey = "null"; while (mysqlDataReader.Read()) { userKey = mysqlDataReader.GetString(1); } serverPacketUserLogin = new ServerPacketUserLogin(NetworkError.NONE, user, userAccountActive, userKey == null ? null: JsonConvert.DeserializeObject <byte[]>(userKey)); } else { serverPacketUserLogin = new ServerPacketUserLogin(NetworkError.SQL_USER_UNKNOWN, null, false, null); } } catch (Exception e) { serverPacketUserLogin = new ServerPacketUserLogin(NetworkError.GLOBAL_UNKNOWN, null, false, null); Console.WriteLine(e.Message); } if (mysqlDataReader != null && !mysqlDataReader.IsClosed) { mysqlDataReader.Close(); } ConsoleHelper.Write("Send - ServerPacketUserLogin"); return(serverPacketUserLogin); }