spectre.console icon indicating copy to clipboard operation
spectre.console copied to clipboard

Customise text prompt for secrets

Open lonix1 opened this issue 3 years ago • 5 comments

Is your feature request related to a problem? Please describe. The text prompt for secrets echoes asterisks (***) to the console.

This is acceptable. But it feels weird on unixy systems, where the traditional secret prompt (sudo) echoes nothing.

Describe the solution you'd like It would be nice to be able to customise the masking character. I would set it to null, so nothing is echoed to the console.

Describe alternatives you've considered /

Additional context /

lonix1 avatar Aug 31 '22 12:08 lonix1

I would like to take a stab at this one if possible.

I am thinking....

I would add a char to TextPrompt that defaults to an asterisk. Maybe named MaskingCharacter. And then whenever we are checking if secret is set instead of using the hardcoded asterisk currently in place, we use the masking character.

Looks like I would need to touch these locations in code.

image

GaryMcD avatar Sep 11 '22 04:09 GaryMcD

Consider whether it's char or char?. It should be nullable so one can type "sudo-style" - i.e. without showing feedback.

The alternative is to allow the NUL char - (char)0 - but that is a non-printing char and could cause unintended issues.

lonix1 avatar Sep 11 '22 06:09 lonix1

I would say public char? Mask { get; set; } = '*'

patriksvensson avatar Sep 11 '22 09:09 patriksvensson

Began working on this.

Question.

The following occurs on line 129 and 210 of TextPrompt.cs IsSecret ? "******" : converter(DefaultValue.Value)

~~I was considering creating a private string with just a get that will create a six character string of whatever the Mask char is, and call that in these two spots instead of the hard coded six asterisk.~~

Actually, why not just make a private method that will "Mask" any string passed to it with the Mask character defined...

Not sure if that's the proper way to resolve?

Then I came to wonder if the string should actually be as long as the default value. So if default value is 5 characters, then the mask of the default value should be 5 characters.

Let me know your thoughts!

GaryMcD avatar Sep 12 '22 22:09 GaryMcD

You can start reviewing what I put together if you like.

https://github.com/spectreconsole/spectre.console/pull/970

GaryMcD avatar Sep 18 '22 02:09 GaryMcD

This has been merged in :) @patriksvensson do we close this?

GaryMcD avatar Sep 26 '22 20:09 GaryMcD

Yes, we should 😁

patriksvensson avatar Sep 26 '22 21:09 patriksvensson

Closed via #970

patriksvensson avatar Sep 26 '22 21:09 patriksvensson

Thanks guys :+1:

lonix1 avatar Sep 27 '22 02:09 lonix1