From 72bcbd8a807157d9a5db5ca0b0123be84dbcd1f5 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 29 Nov 2019 18:32:10 -0600 Subject: [PATCH] fixes #974 password placeholder showPassword() optional --- WiFiManager.cpp | 18 ++++++++++++++++++ WiFiManager.h | 3 +++ .../OnDemandConfigPortal.ino | 7 +++++-- strings_en.h | 4 ++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 6af090b..6844b27 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -974,6 +974,13 @@ void WiFiManager::handleWifi(boolean scan) { pitem = FPSTR(HTTP_FORM_WIFI); pitem.replace(FPSTR(T_v), WiFi_SSID()); + + if(_showPassword){ + pitem.replace(FPSTR(T_p), WiFi_psk()); + } + else { + pitem.replace(FPSTR(T_p),FPSTR(S_passph)); + } page += pitem; page += getStaticOut(); @@ -2195,6 +2202,17 @@ void WiFiManager::setShowDnsFields(boolean alwaysShow){ _staShowDns = alwaysShow ? 1 : 0; } +/** + * toggle showing password in wifi password field + * if not enabled, placeholder will be S_passph + * @since $dev + * @access public + * @param boolean alwaysShow [false] + */ +void WiFiManager::setShowPassword(boolean show){ + _showPassword = show; +} + /** * toggle captive portal * if enabled, then devices that use captive portal checks will be redirected to root diff --git a/WiFiManager.h b/WiFiManager.h index 57b6c00..9af9c03 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -239,6 +239,8 @@ class WiFiManager void setShowStaticFields(boolean alwaysShow); //if true, always show static dns, esle only show if set via setSTAStaticIPConfig void setShowDnsFields(boolean alwaysShow); + // toggle showing the saved wifi password in wifi form, could be a security issue. + void setShowPassword(boolean show); //if false, disable captive portal redirection void setCaptivePortalEnable(boolean enabled); //if false, timeout captive portal even if a STA client connected to softAP (false), suggest disabling if captiveportal is open @@ -355,6 +357,7 @@ class WiFiManager int _staShowStaticFields = 0; // ternary 1=always show static ip fields, 0=only if set, -1=never(cannot change ips via web!) int _staShowDns = 0; // ternary 1=always show dns, 0=only if set, -1=never(cannot change dns via web!) boolean _removeDuplicateAPs = true; // remove dup aps from wifiscan + boolean _showPassword = false; // show or hide saved password on wifi form, might be a security issue! boolean _shouldBreakAfterConfig = false; // stop configportal on save failure boolean _configPortalIsBlocking = true; // configportal enters blocking loop boolean _enableCaptivePortal = true; // enable captive portal redirection diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 98a3a56..1e37d80 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -192,6 +192,9 @@ void setup() { // set AP hidden // wm.setAPHidden(true); + // show password publicly! + // wm.setShowPassword(true); + // set configrportal timeout wm.setConfigPortalTimeout(120); // wm.startConfigPortal("AutoConnectAP", "password"); @@ -202,7 +205,7 @@ void setup() { //and goes into a blocking loop awaiting configuration print_oled(F("Connecting..."),2); - if(!wm.autoConnect("AutoConnectAP")) { + if(!wm.autoConnect("WM_AutoConnectAP")) { Serial.println("failed to connect and hit timeout"); print_oled("Not Connected",2); } @@ -211,7 +214,7 @@ void setup() { Serial.println("TEST_CP ENABLED"); // start configportal always wm.setConfigPortalTimeout(60); - wm.startConfigPortal(); + wm.startConfigPortal("WM_ConnectAP"); } else { //if you get here you have connected to the WiFi diff --git a/strings_en.h b/strings_en.h index f33dd60..d138770 100644 --- a/strings_en.h +++ b/strings_en.h @@ -47,7 +47,7 @@ const char HTTP_ITEM[] PROGMEM = "
{v} {R} {r}% {q} {e}
"; // test all tokens const char HTTP_FORM_START[] PROGMEM = "
"; -const char HTTP_FORM_WIFI[] PROGMEM = "
"; +const char HTTP_FORM_WIFI[] PROGMEM = "
"; const char HTTP_FORM_WIFI_END[] PROGMEM = ""; const char HTTP_FORM_STATIC_HEAD[] PROGMEM = "

"; const char HTTP_FORM_END[] PROGMEM = "

"; @@ -189,7 +189,7 @@ const char S_disable[] PROGMEM = "Disabled"; const char S_GET[] PROGMEM = "GET"; const char S_POST[] PROGMEM = "POST"; const char S_NA[] PROGMEM = "Unknown"; - +const char S_passph[] PROGMEM = "********"; const char S_titlewifisaved[] PROGMEM = "Credentials Saved"; const char S_titlewifi[] PROGMEM = "Config ESP"; const char S_titleinfo[] PROGMEM = "Info";