Password Card


A secure input card for collecting and storing sensitive text data like passwords or secrets. Masks input values on the dashboard for enhanced privacy and security.
Initializer
To create a password card in ESP-DASH v5, use the dash::PasswordCard
class. The value type is always const char*
.
Example:
dash::PasswordCard password(dashboard, "Test Pass");
Callback
Password card supports a callback that is triggered when the input value changes. This allows you to handle user input dynamically. Please pay close attention to the type of the callback parameter, which is std::optional<T>
. This results in the callback receiving std::nullopt
when the input is cleared or invalid, very useful for handling user input gracefully.
password.onChange([](const std::optional<const char*>& value) {
// Handle password input
if (value) {
Serial.printf("Password entered: %s\n", *value);
} else {
Serial.println("Password cleared");
}
});
Methods
setValue(const char* password)
Set the password value.
passwordCard.setValue("secret");
- Signature:
void setValue(const char* password)
- Parameters:
const char* password
— The password value to set.
- Returns:
void
value()
Get the current password value.
const char* pwd = passwordCard.value();
- Signature:
const char* value()
- Parameters: None
- Returns:
const char*
— The current password value.
Reference
Below is a reference code showing how to integrate this widget in a real project, including initialization and value updates usage.
// ...
// Create a password card
dash::PasswordCard passwordCard(dashboard, "Test Pass");
void setup() {
// ...
// Register callback for password input
password.onChange([](const char* value) {
Serial.printf("Password entered: %s\n", value);
// Use password securely
});
// Optionally set password value
password.setValue("secret");
}
void loop() {
// ...
}