Refactor MQTTBridge configuration validation to support optional username and password

- Simplified validation logic in MQTTBridge to only reject default placeholder values for username and password.
- Removed unnecessary checks for empty username and password, allowing for anonymous mode support.
This commit is contained in:
agessaman committed 2026-01-03 09:34:43 -08:00
1 parent e754317ceb
commit d1093b4390
1 file changed
+8 -12
+8 -12
View File
@@ -352,15 +352,13 @@ bool MQTTBridge::isConfigValid(const NodePrefs* prefs) {
return false;
}
// Check if MQTT username is configured (not default placeholder)
if (strlen(prefs->mqtt_username) == 0 ||
strcmp(prefs->mqtt_username, "your-username") == 0) {
// Username and password are optional - anonymous mode is supported
// Only reject if they contain the default placeholder values
if (strcmp(prefs->mqtt_username, "your-username") == 0) {
return false;
}
// Check if MQTT password is configured (not default placeholder)
if (strlen(prefs->mqtt_password) == 0 ||
strcmp(prefs->mqtt_password, "your-password") == 0) {
if (strcmp(prefs->mqtt_password, "your-password") == 0) {
return false;
}
@@ -566,15 +564,13 @@ bool MQTTBridge::isMQTTConfigValid() {
return false;
}
// Check if MQTT username is configured (not default placeholder)
if (strlen(_prefs->mqtt_username) == 0 ||
strcmp(_prefs->mqtt_username, "your-username") == 0) {
// Username and password are optional - anonymous mode is supported
// Only reject if they contain the default placeholder values
if (strcmp(_prefs->mqtt_username, "your-username") == 0) {
return false;
}
// Check if MQTT password is configured (not default placeholder)
if (strlen(_prefs->mqtt_password) == 0 ||
strcmp(_prefs->mqtt_password, "your-password") == 0) {
if (strcmp(_prefs->mqtt_password, "your-password") == 0) {
return false;
}