LogoCyanPrint

Ask Password Questions

How to ask for hidden password/secret input

How to Ask Password Questions

Use password questions for sensitive input that should be hidden from display.

Shorthand Form

const apiKey = await i.password(
'Enter API key', // Question text shown to user
'secrets.apiKey', // Unique key for caching
'Your API key' // Optional help text
);
api_key = await i.password(
'Enter API key', # Question text shown to user
'secrets.apiKey', # Unique key for caching
'Your API key' # Optional help text
)
var apiKey = await i.Password(
"Enter API key", // Question text shown to user
"secrets.apiKey", // Unique key for caching
"Your API key" // Optional help text
);

Object Form

const apiKey = await i.password({
type: QuestionType.Password,
id: 'secrets.apiKey',
message: 'Enter API key',
desc: 'Your secret API key',
validate: (input) => {
if (!input) return 'API key is required';
if (input.length < 20) return 'API key seems too short';
return null;
}
});
api_key = await i.password(
type=QuestionType.PASSWORD,
id='secrets.apiKey',
message='Enter API key',
desc='Your secret API key',
validate=lambda inp: (
None if inp and len(inp) >= 20
else 'API key is required' if not inp
else 'API key seems too short'
)
)
var apiKey = await i.Password(new PasswordQuestion {
Type = QuestionType.Password,
Id = "secrets.apiKey",
Message = "Enter API key",
Desc = "Your secret API key",
Validate = input => {
if (string.IsNullOrEmpty(input)) return "API key is required";
if (input.Length < 20) return "API key seems too short";
return null;
}
});

Password Confirmation

Require users to enter the password twice for verification.

const password = await i.password({
type: QuestionType.Password,
id: 'secrets.password',
message: 'Create password',
desc: 'You will be asked to confirm',
confirmation: true
});
password = await i.password(
type=QuestionType.PASSWORD,
id='secrets.password',
message='Create password',
desc='You will be asked to confirm',
confirmation=True
)
var password = await i.Password(new PasswordQuestion {
Type = QuestionType.Password,
Id = "secrets.password",
Message = "Create password",
Desc = "You will be asked to confirm",
Confirmation = true
});

Validation Patterns

const password = await i.password({
type: QuestionType.Password,
id: 'secrets.password',
message: 'Enter password',
desc: 'Choose a strong password',
validate: (input) => {
if (input.length < 8) return 'At least 8 characters';
if (!/[A-Z]/.test(input)) return 'Include an uppercase letter';
if (!/[0-9]/.test(input)) return 'Include a number';
return null;
}
});
import re
password = await i.password(
type=QuestionType.PASSWORD,
id='secrets.password',
message='Enter password',
desc='Choose a strong password',
validate=lambda inp: (
'At least 8 characters' if len(inp) < 8
else 'Include an uppercase letter' if not re.search(r'[A-Z]', inp)
else 'Include a number' if not re.search(r'[0-9]', inp)
else None
)
)
using System.Text.RegularExpressions;
var password = await i.Password(new PasswordQuestion {
Type = QuestionType.Password,
Id = "secrets.password",
Message = "Enter password",
Desc = "Choose a strong password",
Validate = input => {
if (input.Length < 8) return "At least 8 characters";
if (!Regex.IsMatch(input, @"[A-Z]")) return "Include an uppercase letter";
if (!Regex.IsMatch(input, @"[0-9]")) return "Include a number";
return null;
}
});

Passwords should never be stored in template output files. Use them for runtime configuration only.