mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-09-12 01:24:04 +00:00
[Password] Add clearPassword command
As suggested here: https://github.com/letscontrolit/ESPEasy/issues/3860
This commit is contained in:
@@ -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>``"
|
||||
"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -27,6 +27,8 @@ struct SecurityStruct
|
||||
|
||||
bool hasWiFiCredentials(WiFiCredentialsSlot slot) const;
|
||||
|
||||
String getPassword() const;
|
||||
|
||||
char WifiSSID[32];
|
||||
char WifiKey[64];
|
||||
char WifiSSID2[32];
|
||||
|
||||
Reference in New Issue
Block a user