Skip to content

Password

Password プロンプトは文字をマスクしながらユーザー入力を受け付けます。

基本的な使い方

csharp
var secret = Prompt.Password("Type new password");
Console.WriteLine("Password OK");

パラメータ

パラメータ説明
messagestringユーザーに表示するメッセージ
passwordCharstring入力をマスクするために使用される文字 (デフォルト: "*")
placeholderstring?入力エリアに表示されるプレースホルダーテキスト
validatorsIList<Func<object?, ValidationResult?>>?入力に適用するバリデータのリスト

Options クラス

csharp
var secret = Prompt.Password(new PasswordOptions
{
    Message = "Type new password",
    Placeholder = "At least 8 characters",
    PasswordChar = "*",
    Validators = { Validators.Required(), Validators.MinLength(8) }
});

Fluent API

csharp
using Sharprompt.Fluent;

var secret = Prompt.Password(o => o.WithMessage("Type new password")
                                   .WithPlaceholder("At least 8 characters")
                                   .AddValidators(Validators.Required(), Validators.MinLength(8)));

バリデーション付き

csharp
var secret = Prompt.Password("Type new password",
    placeholder: "At least 8 characters",
    validators: new[] { Validators.Required(), Validators.MinLength(8) });

Released under the MIT License.