← Back to Home • Next: Secret — Methods →
Single-line, masked text entry. The user types, each character is hidden behind a mask symbol, and they confirm with Enter.
The Secret control is the masked sibling of Input. Use it whenever the
value must not appear on screen — a password, an API key, a PIN, a connection string, a token. It
shares the same live filtering, case coercion, length cap, and confirmation-time validation as
Input, but replaces every typed character with a mask symbol and can optionally let the user peek
at the plain text with F2.
⚠️
Secretdeliberately omits the persistence features ofInput(no history, no autocomplete, no seeded default). A secret should never be written to disk or offered as a suggestion — see the security note in Operations.
| Sub-page | What you will find |
|---|---|
| Index (this page) | What it is, when to use it, a first working example, the method map |
| Methods | Every fluent method — signature, parameters, defaults, and a snippet |
| Operations | Keyboard, the mask character, F2 reveal, validation flow, and the security note |
| Styles | The InputStyles regions and how to recolor them |
Use Secret when… |
Consider instead… |
|---|---|
| The value is a password, key, PIN, or token | — |
| The value is ordinary free-form text | Input |
| The value must match a fixed pattern (date, phone, currency) | MaskEdit |
| The user should pick from a known list | Select |
using PromptPlusLibrary;
var result = PromptPlus.Controls
.Secret("Password")
.Run();
if (!result.IsAborted)
PromptPlus.Console.WriteLine("Password captured.");
Secret("Password") creates the control. The first argument is the prompt; an optional
second argument is a description line shown under it..Run() renders the masked field and blocks until the user presses Enter (confirm) or
Esc (abort).ResultPrompt<string>: read .Content
for the entered text and .IsAborted to detect Esc.⚠️ Always check
IsAbortedbefore using.Content. On abort,.Contentis NOT guaranteed to be empty — it holds whatever partial text was typed before Esc was pressed. Treat it as sensitive and discard it; don’t assume it’s safe to leave lying around just because the user aborted. Never echo.Contentto the console — the example above prints a confirmation, not the value.
using PromptPlusLibrary;
using ConsolePlusLibrary; // Color, InputStyles-agnostic types
var pin = PromptPlus.Controls
.Secret("PIN", "Only 4 digits are accepted")
.MaskSecret('*', enabledView: false) // hide with '*', no F2 reveal
.AcceptInput(char.IsDigit) // reject any non-digit keystroke
.MaxLength(4) // stop accepting after 4 characters
.PredicateValid(v => v.Length == 4
? (true, null)
: (false, "PIN must be exactly 4 digits")) // validate on Enter
.Run();
if (!pin.IsAborted)
PromptPlus.Console.WriteLine("PIN accepted.");
This combines the four most common building blocks: a custom mask with reveal disabled
(MaskSecret), per-keystroke filtering (AcceptInput), a hard length cap (MaxLength),
and confirmation-time validation with a message (PredicateValid). See
Operations for how they interact.
Grouped by purpose. Full signatures and examples are on the Methods page.
| Purpose | Methods |
|---|---|
| Masking & reveal | MaskSecret |
| Restrict typing | AcceptInput, MaxLength, InputToCase |
| Validate on confirm | PredicateValid, PredicateValidAsync |
| Dynamic description | ChangeDescription, ChangeDescriptionAsync |
| Appearance & behavior | Styles, Options |
| Run | Run |
Unlike
Input,Secrethas noDefault,DefaultIfEmpty,EnableHistory, or suggestion methods — by design.
Secret returns ResultPrompt<string>.
| Member | Meaning |
|---|---|
.Content |
The confirmed text — or whatever partial text was typed before an abort, not necessarily empty |
.IsAborted |
true when the user pressed Esc / the abort key |
var (secret, aborted) = PromptPlus.Controls.Secret("Token").Run();
if (!aborted) UseToken(secret); // consume it — do not print it