Skip to content
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

Adding custom and masked password fields in the AP Config page for custom password variables - Solution to issue #33 #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 30 additions & 2 deletions WiFiSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ namespace { // Helpers
}
};

struct WiFiSettingsPasswordString : WiFiSettingsParameter {
virtual void set(const String& v) { value = v; }
String html() {
String h = F("<p><label>{label}:<br><input name='{name}' value='##**##**##**' placeholder='{init}' minlength={min} maxlength={max}></label>");
h.replace("{name}", html_entities(name));
h.replace("{init}", html_entities(init));
h.replace("{label}", html_entities(label));
h.replace("{min}", String(min));
h.replace("{max}", String(max));
return h;
}
};

struct WiFiSettingsInt : WiFiSettingsParameter {
virtual void set(const String& v) { value = v; }
String html() {
Expand Down Expand Up @@ -174,6 +187,18 @@ String WiFiSettingsClass::string(const String& name, unsigned int min_length, un
return rv;
}

String WiFiSettingsClass::passwordstring(const String& name, const String& init, const String& label) {
begin();
struct WiFiSettingsPasswordString* x = new WiFiSettingsPasswordString();
x->name = name;
x->label = label.length() ? label : name;
x->init = init;
x->fill();

params.push_back(x);
return x->value.length() ? x->value : x->init;
}

long WiFiSettingsClass::integer(const String& name, long init, const String& label) {
begin();
struct WiFiSettingsInt* x = new WiFiSettingsInt();
Expand Down Expand Up @@ -408,8 +433,11 @@ void WiFiSettingsClass::portal() {
}

for (auto& p : params) {
p->set(http.arg(p->name));
if (! p->store()) ok = false;
String pwstring = http.arg(p->name);
if (pwstring != "##**##**##**"){
p->set(http.arg(p->name));
if (! p->store()) ok = false;
}
}

if (ok) {
Expand Down
1 change: 1 addition & 0 deletions WiFiSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class WiFiSettingsClass {
String string(const String& name, const String& init = "", const String& label = "");
String string(const String& name, unsigned int max_length, const String& init = "", const String& label = "");
String string(const String& name, unsigned int min_length, unsigned int max_length, const String& init = "", const String& label = "");
String passwordstring(const String& name, const String& init = "", const String& label = "");
long integer(const String& name, long init = 0, const String& label = "");
long integer(const String& name, long min, long max, long init = 0, const String& label = "");
bool checkbox(const String& name, bool init = false, const String& label = "");
Expand Down