Skip to content
ConsoleMonster
Class

SecretPrompt

ConsoleMonster.Interactive

Namespace
ConsoleMonster.Interactive
Assembly
ConsoleMonster
Modifiers
sealed

A secret (password, token): masked or hidden while typed, with Ctrl+R to reveal it for a moment, required by default. The answer never appears in summaries, logs or presets.

Inheritance

Usage

Explore 36 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Accepted by parameters 18

Constructors

public SecretPrompt(string title) #

Creates a secret prompt.

Parameters

title string required
The question.

Methods

public override string Describe(string value) #

The answer as text, for the summary line left in the scrollback.

Parameters

value string required
The answer.

Returns

string The text.
public SecureString ShowSecure(InteractiveOptions? options = null, CancellationToken cancellationToken = default) #

Asks for the secret and returns it as a read-only SecureString, for APIs that take one (credentials, certificate stores). The answer is edited as text first, so this is a type for those APIs, not stronger protection than Prompt<T>.Show.

Parameters

options ConsoleMonster.Interactive.InteractiveOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
Cancels the prompt.

Returns

SecureString The secret.

Properties

public SecretDisplay Display { get; set; } #

How the secret is shown while typed.

public bool AllowReveal { get; set; } #

Whether Ctrl+R can reveal the typed text.

public bool Required { get; set; } #

Whether an empty answer is refused.

public int MinLength { get; set; } #

The fewest characters accepted.

public Func<string, string?>? Validator { get; set; } #
Fluent("Validate")

A validator: returns an error message, or null.

Extension Methods

public static SecretPrompt AllowReveal(SecretPrompt secretPrompt, bool value = true) #

Sets SecretPrompt.AllowReveal: Whether Ctrl+R can reveal the typed text.

Parameters

secretPrompt ConsoleMonster.Interactive.SecretPrompt required
The instance.
value bool = true optional
The value; true when omitted.

Returns

SecretPrompt The same instance.

Examples

// C# initializer or property        // C# fluent
secretPrompt.AllowReveal = value;    secretPrompt.AllowReveal(value);
public static SecretPrompt Default(SecretPrompt secretPrompt, string value) #

Sets Prompt<string>.Default: The default answer: pre-selected, accepted with Enter, and returned in non-interactive sessions.

Parameters

secretPrompt ConsoleMonster.Interactive.SecretPrompt required
The instance.
value string required
The value.

Returns

SecretPrompt The same instance.

Examples

// C# initializer or property    // C# fluent
secretPrompt.Default = value;    secretPrompt.Default(value);
public static SecretPrompt Description(SecretPrompt secretPrompt, string? value) #

Sets Prompt<string>.Description: Help text under the question.

Parameters

secretPrompt ConsoleMonster.Interactive.SecretPrompt required
The instance.
value string? required
The value.

Returns

SecretPrompt The same instance.

Examples

// C# initializer or property        // C# fluent
secretPrompt.Description = value;    secretPrompt.Description(value);
public static SecretPrompt Display(SecretPrompt secretPrompt, SecretDisplay value) #

Sets SecretPrompt.Display: How the secret is shown while typed.

Parameters

secretPrompt ConsoleMonster.Interactive.SecretPrompt required
The instance.
value ConsoleMonster.Interactive.SecretDisplay required
The value.

Returns

SecretPrompt The same instance.

Examples

// C# initializer or property    // C# fluent
secretPrompt.Display = value;    secretPrompt.Display(value);
public static SecretPrompt MinLength(SecretPrompt secretPrompt, int value) #

Sets SecretPrompt.MinLength: The fewest characters accepted.

Parameters

secretPrompt ConsoleMonster.Interactive.SecretPrompt required
The instance.
value int required
The value.

Returns

SecretPrompt The same instance.

Examples

// C# initializer or property      // C# fluent
secretPrompt.MinLength = value;    secretPrompt.MinLength(value);
public static SecretPrompt ParameterName(SecretPrompt secretPrompt, string? value) #

Sets Prompt<string>.ParameterName: The parameter that supplies this value non-interactively (-Domain, --domain); named in the non-interactive error message.

Parameters

secretPrompt ConsoleMonster.Interactive.SecretPrompt required
The instance.
value string? required
The value.

Returns

SecretPrompt The same instance.

Examples

// C# initializer or property          // C# fluent
secretPrompt.ParameterName = value;    secretPrompt.ParameterName(value);
public static SecretPrompt Required(SecretPrompt secretPrompt, bool value = true) #

Sets SecretPrompt.Required: Whether an empty answer is refused.

Parameters

secretPrompt ConsoleMonster.Interactive.SecretPrompt required
The instance.
value bool = true optional
The value; true when omitted.

Returns

SecretPrompt The same instance.

Examples

// C# initializer or property     // C# fluent
secretPrompt.Required = value;    secretPrompt.Required(value);
public static SecretPrompt Title(SecretPrompt secretPrompt, string value) #

Sets Prompt<string>.Title: The question.

Parameters

secretPrompt ConsoleMonster.Interactive.SecretPrompt required
The instance.
value string required
The value.

Returns

SecretPrompt The same instance.

Examples

// C# initializer or property    // C# fluent
secretPrompt.Title = value;      secretPrompt.Title(value);
public static SecretPrompt Validate(SecretPrompt secretPrompt, Func<string, string?>? value) #

Sets SecretPrompt.Validator: A validator: returns an error message, or null.

Parameters

secretPrompt ConsoleMonster.Interactive.SecretPrompt required
The instance.
value System.Func<string, string?>? required
The callback.

Returns

SecretPrompt The same instance.

Examples

// C# initializer or property      // C# fluent
secretPrompt.Validator = value;    secretPrompt.Validate(value);