From 1911b76b236d522deddf6b11d4e435abd1c35807 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sat, 18 Aug 2018 19:26:18 +0200 Subject: [PATCH] Correct serialization of encrypted passwords --- ArchiSteamFarm/BotConfig.cs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/ArchiSteamFarm/BotConfig.cs b/ArchiSteamFarm/BotConfig.cs index cf51a2710..9fe7dcee2 100644 --- a/ArchiSteamFarm/BotConfig.cs +++ b/ArchiSteamFarm/BotConfig.cs @@ -149,8 +149,26 @@ namespace ArchiSteamFarm { [JsonProperty] internal string SteamParentalPIN { get; set; } = DefaultSteamParentalPIN; - [JsonProperty] - internal string SteamPassword { get; set; } = DefaultSteamPassword; + internal string SteamPassword { + get { + if (string.IsNullOrEmpty(_SteamPassword)) { + return null; + } + + return PasswordFormat == CryptoHelper.ECryptoMethod.PlainText ? _SteamPassword : CryptoHelper.Decrypt(PasswordFormat, _SteamPassword); + } + set { + if (string.IsNullOrEmpty(value)) { + ASF.ArchiLogger.LogNullError(nameof(value)); + return; + } + + _SteamPassword = PasswordFormat == CryptoHelper.ECryptoMethod.PlainText ? value : CryptoHelper.Encrypt(PasswordFormat, value); + } + } + + [JsonProperty(PropertyName = nameof(SteamPassword))] + private string _SteamPassword = DefaultSteamPassword; private bool ShouldSerializeSensitiveDetails = true; @@ -252,12 +270,6 @@ namespace ArchiSteamFarm { return null; } - // Support encrypted passwords - if ((botConfig.PasswordFormat != CryptoHelper.ECryptoMethod.PlainText) && !string.IsNullOrEmpty(botConfig.SteamPassword)) { - // In worst case password will result in null, which will have to be corrected by user during runtime - botConfig.SteamPassword = CryptoHelper.Decrypt(botConfig.PasswordFormat, botConfig.SteamPassword); - } - botConfig.ShouldSerializeEverything = false; botConfig.ShouldSerializeSensitiveDetails = false; return botConfig;