Correct serialization of encrypted passwords

This commit is contained in:
JustArchi
2018-08-18 19:26:18 +02:00
parent 1a2cbf3dad
commit 1911b76b23

View File

@@ -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;