Skip to content

Avoid starting AP Mode even when the password is too short #7832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ void setup() {
Serial.println("Configuring access point...");

// You can remove the password parameter if you want the AP to be open.
WiFi.softAP(ssid, password);
// a valid password must have more than 7 characters
if (!WiFi.softAP(ssid, password)) {
log_e("Soft AP creation failed.");
while(1);
}
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
Expand Down
13 changes: 7 additions & 6 deletions libraries/WiFi/src/WiFiAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ void wifi_softap_config(wifi_config_t *wifi_config, const char * ssid=NULL, cons
bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder)
{

if(!WiFi.enableAP(true)) {
// enable AP failed
log_e("enable AP first!");
return false;
}

if(!ssid || *ssid == 0) {
// fail SSID missing
log_e("SSID missing!");
Expand All @@ -154,6 +148,13 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel,
return false;
}

// last step after checking the SSID and password
if(!WiFi.enableAP(true)) {
// enable AP failed
log_e("enable AP first!");
return false;
}

wifi_config_t conf;
wifi_config_t conf_current;
wifi_softap_config(&conf, ssid, passphrase, channel, WIFI_AUTH_WPA2_PSK, ssid_hidden, max_connection, ftm_responder);
Expand Down