[Password] Add clearPassword command

As suggested here: https://github.com/letscontrolit/ESPEasy/issues/3860
This commit is contained in:
TD-er
2021-12-03 16:13:20 +01:00
parent 549f76e23f
commit 6fcbdeb461
6 changed files with 38 additions and 1 deletions
+10 -1
View File
@@ -50,6 +50,14 @@
See also ``AccessInfo``.
``ClearAccessBlock``"
"
ClearPassword","
:red:`Internal`","
Clear the password of the unit.
See also ``Password``.
``ClearPassword,<current password>``"
"
ClearRTCram","
:red:`Internal`","
@@ -287,7 +295,8 @@
"
Password","
:red:`Internal`","
Set the password of the unit
Set the password of the unit.
See also ``ClearPassword``.
``Password,<new password>``"
"
+1
View File
@@ -268,6 +268,7 @@ bool executeInternalCommand(command_case_data & data)
}
case 'c': {
COMMAND_CASE_R( "clearaccessblock", Command_AccessInfo_Clear, 0); // Network Command
COMMAND_CASE_R( "clearpasword", Command_Settings_Password_Clear, 1); // Settings.h
COMMAND_CASE_R( "clearrtcram", Command_RTC_Clear, 0); // RTC.h
COMMAND_CASE_R( "config", Command_Task_RemoteConfig, -1); // Tasks.h
COMMAND_CASE_R("controllerdisable", Command_Controller_Disable, 1); // Controller.h
+14
View File
@@ -62,6 +62,20 @@ String Command_Settings_Password(struct EventStruct *event, const char* Line)
);
}
String Command_Settings_Password_Clear(struct EventStruct *event, const char* Line)
{
const String storedPassword = SecuritySettings.getPassword();
if (storedPassword.length() > 0) {
// There is a password set, so we must check it.
const String password = parseStringKeepCase(Line, 2);
if (!storedPassword.equals(password)) {
return return_command_failed();
}
ZERO_FILL(SecuritySettings.Password);
}
return return_command_success();
}
const __FlashStringHelper * Command_Settings_Save(struct EventStruct *event, const char* Line)
{
SaveSettings();
+1
View File
@@ -7,6 +7,7 @@ String Command_Settings_Build(struct EventStruct *event, const char* Line);
String Command_Settings_Unit(struct EventStruct *event, const char* Line);
String Command_Settings_Name(struct EventStruct *event, const char* Line);
String Command_Settings_Password(struct EventStruct *event, const char* Line);
String Command_Settings_Password_Clear(struct EventStruct *event, const char* Line);
const __FlashStringHelper * Command_Settings_Save(struct EventStruct *event, const char* Line);
const __FlashStringHelper * Command_Settings_Load(struct EventStruct *event, const char* Line);
const __FlashStringHelper * Command_Settings_Print(struct EventStruct *event, const char* Line);
+10
View File
@@ -68,3 +68,13 @@ bool SecurityStruct::hasWiFiCredentials(SecurityStruct::WiFiCredentialsSlot slot
}
return false;
}
String SecurityStruct::getPassword() const {
String res;
const size_t passLength = strnlen(Password, sizeof(Password));
res.reserve(passLength);
for (size_t i = 0; i < passLength; ++i) {
res += Password[i];
}
return res;
}
+2
View File
@@ -27,6 +27,8 @@ struct SecurityStruct
bool hasWiFiCredentials(WiFiCredentialsSlot slot) const;
String getPassword() const;
char WifiSSID[32];
char WifiKey[64];
char WifiSSID2[32];