From 6e64d653c5f775c37c951e35452b8fdccc86ccd4 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Fri, 8 Mar 2019 23:48:49 +0100 Subject: [PATCH] Hide connect password from logs. --- Source/MQTTnet/Packets/MqttConnectPacket.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/MQTTnet/Packets/MqttConnectPacket.cs b/Source/MQTTnet/Packets/MqttConnectPacket.cs index 8c7ae464..18893977 100644 --- a/Source/MQTTnet/Packets/MqttConnectPacket.cs +++ b/Source/MQTTnet/Packets/MqttConnectPacket.cs @@ -27,7 +27,13 @@ public override string ToString() { - return string.Concat("Connect: [ProtocolLevel=", ProtocolLevel, "] [ClientId=", ClientId, "] [Username=", Username, "] [Password=", Password, "] [KeepAlivePeriod=", KeepAlivePeriod, "] [CleanSession=", CleanSession, "]"); + var password = Password; + if (!string.IsNullOrEmpty(password)) + { + password = "****"; + } + + return string.Concat("Connect: [ProtocolLevel=", ProtocolLevel, "] [ClientId=", ClientId, "] [Username=", Username, "] [Password=", password, "] [KeepAlivePeriod=", KeepAlivePeriod, "] [CleanSession=", CleanSession, "]"); } } }