From 1dcf98c849266844c617c939eadb7d6f571ca60a Mon Sep 17 00:00:00 2001 From: Archi Date: Fri, 29 Apr 2022 17:55:33 +0200 Subject: [PATCH] Fix SteamPassword input Asking for password with encryption enabled always resulted in an error, as the password wasn't properly set to the plaintext and we were back to square one. The previous logic was overly complex, I don't know why, this should achieve the same and be much easier to understand while at it. --- ArchiSteamFarm/IPC/Controllers/Api/BotController.cs | 5 ++++- ArchiSteamFarm/Steam/Bot.cs | 11 ++++++++++- ArchiSteamFarm/Steam/Storage/BotConfig.cs | 13 ++----------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ArchiSteamFarm/IPC/Controllers/Api/BotController.cs b/ArchiSteamFarm/IPC/Controllers/Api/BotController.cs index 04abb291b..2517d677f 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/BotController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/BotController.cs @@ -123,7 +123,10 @@ public sealed class BotController : ArchiController { } if (!request.BotConfig.IsSteamPasswordSet && bot.BotConfig.IsSteamPasswordSet) { - request.BotConfig.SetDecryptedSteamPassword(await bot.BotConfig.GetDecryptedSteamPassword().ConfigureAwait(false)); + request.BotConfig.SteamPassword = bot.BotConfig.SteamPassword; + + // Since we're inheriting the password, we should also inherit the format, whatever that might be + request.BotConfig.PasswordFormat = bot.BotConfig.PasswordFormat; } if (!request.BotConfig.IsSteamParentalCodeSet && bot.BotConfig.IsSteamParentalCodeSet) { diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index 3cd9fbf62..3944dcc0f 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -860,13 +860,20 @@ public sealed class Bot : IAsyncDisposable { switch (inputType) { case ASF.EUserInputType.Login: BotConfig.SteamLogin = inputValue; + + // Do not allow saving this account credential BotConfig.IsSteamLoginSet = false; break; case ASF.EUserInputType.Password: - BotConfig.SetDecryptedSteamPassword(inputValue); + BotConfig.SteamPassword = inputValue; + + // Do not allow saving this account credential BotConfig.IsSteamPasswordSet = false; + // If by any chance user has wrongly configured password format, we reset it back to plaintext + BotConfig.PasswordFormat = ArchiCryptoHelper.ECryptoMethod.PlainText; + break; case ASF.EUserInputType.SteamGuard: if (inputValue.Length != 5) { @@ -882,6 +889,8 @@ public sealed class Bot : IAsyncDisposable { } BotConfig.SteamParentalCode = inputValue; + + // Do not allow saving this account credential BotConfig.IsSteamParentalCodeSet = false; break; diff --git a/ArchiSteamFarm/Steam/Storage/BotConfig.cs b/ArchiSteamFarm/Steam/Storage/BotConfig.cs index 4e0058528..019e33804 100644 --- a/ArchiSteamFarm/Steam/Storage/BotConfig.cs +++ b/ArchiSteamFarm/Steam/Storage/BotConfig.cs @@ -196,7 +196,7 @@ public sealed class BotConfig { public EPersonaState OnlineStatus { get; private set; } = DefaultOnlineStatus; [JsonProperty(Required = Required.DisallowNull)] - public ArchiCryptoHelper.ECryptoMethod PasswordFormat { get; private set; } = DefaultPasswordFormat; + public ArchiCryptoHelper.ECryptoMethod PasswordFormat { get; internal set; } = DefaultPasswordFormat; [JsonProperty(Required = Required.DisallowNull)] public bool Paused { get; private set; } = DefaultPaused; @@ -524,7 +524,7 @@ public sealed class BotConfig { return null; } - if (PasswordFormat == ArchiCryptoHelper.ECryptoMethod.PlainText) { + if (!PasswordFormat.HasTransformation()) { return SteamPassword; } @@ -631,15 +631,6 @@ public sealed class BotConfig { return (botConfig, json != latestJson ? latestJson : null); } - internal void SetDecryptedSteamPassword(string? decryptedSteamPassword) { - if (!string.IsNullOrEmpty(decryptedSteamPassword) && PasswordFormat.HasTransformation()) { - // ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework - decryptedSteamPassword = ArchiCryptoHelper.Encrypt(PasswordFormat, decryptedSteamPassword!); - } - - SteamPassword = decryptedSteamPassword; - } - public enum EAccess : byte { None, FamilySharing,