C4 Engine
C4 Engine API Documentation

class PasswordWidget

Defined in:  C4Widgets.h
The PasswordWidget class represents an interface widget that displays an editable text box for passwords.
Definition

class PasswordWidget final : public EditTextWidget

Member Functions
PasswordWidget::GetPassword Returns the password entered into the editable text box.
Constructor

PasswordWidget(const Vector2D& size, int32 charCount, const char *font = nullptrfloat em = kDefaultFontSize, bool secure = false);

Parameters
size The size of the text box, in pixels.
charCount The maximum number of characters that can be entered into the text box.
font The name of the font in which the password dots are displayed.
em The em size of the font, in pixels.
secure Indicates whether security features are enabled.
Description
The PasswordWidget class is a special type of EditTextWidget that is intended for password entry. The specific characteristics that differentiate a password widget from an ordinary editable text widget are as follows.

1. The text displayed in the text box is always a sequence of dot characters (Unicode value U+2022).
2. If the user attempts to copy text from a password widget, then only the dot characters are copied.
3. If security features are enabled, the memory occupied by the actual password text is locked in physical memory during the lifetime of the password widget, and the memory is immediately erased when the password widget is destroyed. This prevents the password from being written to a swap file or persisting in unallocated memory.

The TextWidget::GetText function cannot retrieve the password string from a password widget. Instead, the PasswordWidget::GetPassword function should be used. If the secure parameter is true, then security features are enabled to prevent the password from being leaked into the swap file or unallocated memory. The security features cannot be enabled or disabled after a password widget has been constructed. An application should ensure that no more than one secure password widget exists at any point in time. This avoids the improbable but possible case that two password widgets use the same virtual page in memory and the destruction of one password widget inadvertently unlocks the memory used by the other password widget.
Base Classes
EditTextWidget The PasswordWidget class is a special type of editable text box.
Wiki Articles

Password Widget