Comments (4)
Case 1:
The current architecture only renders a new frame after a key press. Doing anything time-based would require a big refactor of the library, so I think the blinking solution would not be completely worth it.
Case 2:
Unfortunately, it looks like it is very difficult to receive key press and key release events from a tty, if not impossible (I didn't look far enough). Also, crossterm
does not support it, which means that if possible, I'd probably have to talk to them to implement it (or do it myself). Anyway, it also looks like a huge effort for something that can be solved with other alternatives.
Finally, I took your Ctrl+R
suggestion and implemented the password display feature by toggling the current "display" mode. If the user presses Ctrl+R, it will display the input as a normal text input. Ctrl+R again and it goes back to nothing being displayed.
Take a look: dfbab54 and let me know what you think.
from inquire.
I think CTRL + R is a great solution for those cases when a new password is created and the user wants to check that there are no typos. Password confirmation is also a good solution, but I agree that it shouldn't be part of the library.
from inquire.
Motivation: Avoid accidental typing errors that will lead to the inability to use a password.
Case 1: If, for some reason, the signal of pressing one or more of the keys is lost (the keystroke was insufficient), the user will not know the entered password. The entered password is different from the password that the user wanted to enter and this can create difficulties.
A possible solution is to provide feedback to the user about the keystroke. A character input event can be displayed by blinking the cursor once or by briefly changing the appearance of the cursor. In general, I am against the possibility of revealing the length of the password. The proposed solution is less in violation of accepted CLI standards and more secure.
Case 2: Accidental key presses next to the pressed key. This will lead to difficulties, as in the previous case.
Possible solution: The user can display the password entered using the keyboard shortcut to verify that the password has been entered correctly. Ideally, there should be a user pressing and holding a specific keyboard shortcut (maybe Ctrl + R? R as reveal, easier to remember). The password should be hidden as soon as the keys are released. It may not be easy to implement, because a tty doesn't know about the concept of key press or key release events. It only knows about 'data stream in' (and out). The proposed solution does not conflict with CLI standards.
So, you can provide the user more options to control and avoid typing errors.
from inquire.
I have also decided to implement this feature as an optional customization for library users, recommending them to not do anything special and follow standard CLI applications :)
Please let me know if using the default display mode (hidden) and allowing the toggling of display mode satisfy your needs of both security, by not revealing any info by default, and convenience, by allowing you to see the current input, just not on key press/release but by pressing the twice the shortcut. For example:
let passwd = Password::new("Password:")
.with_display_toggle_enabled()
.with_display_mode(PasswordDisplayMode::Hidden) // default value but mentioned here to make it explicit
.with_validator(min_length!(10))
.with_formatter(&|_| String::from("Password received"))
.with_help_message("It is recommended to generate a new one only for this purpose")
.prompt()?;
let confirmation = Password::new("Confirmation:")
.with_display_toggle_enabled()
.with_display_mode(PasswordDisplayMode::Hidden) // default value but mentioned here to make it explicit
.with_formatter(&|_| String::from("Confirmation received"))
.with_help_message("It is recommended to generate a new one only for this purpose")
.prompt()?;
if password == confirmation {
Ok(password)
} else {
Err(())
}
from inquire.
Related Issues (20)
- Release HOT 1
- Use tty instead of stdin HOT 1
- with_starting_cursor does not apply HOT 2
- Fully support piped inputs in parallel with interactive inputs.
- Prompt crashes if program is run with crossterm+piped input+macos
- Add code coverage metrics to get a better idea of test coverage
- inquire derive and attribute macro HOT 3
- Show proper error message for CustomType prompt HOT 1
- Alt+{left, right, backspace} support HOT 3
- DateSelect default help message incorrect ? HOT 2
- Support for up-arrow previous prompt history, and control-keys HOT 2
- Inquire leaves the terminal in a broken state HOT 3
- Render issue using the `console` backend HOT 2
- Inquire forgets to add newlines in 0.7.1 HOT 5
- "external_print" Functionality
- Make Scrolling More Obvious (Customizable maybe?) HOT 1
- MultiSelect list doesn't show after filter is cleared on selection HOT 1
- Suppressing static lifetimes from Text (and other modules ?) HOT 1
- typo in README for termion link
- Password prompt with redirected `stdout`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inquire.