conradkleinespel / rpassword

Cross platform Rust library to read a password in the terminal (Linux, BSD, OSX, Windows, WASM).
Apache License 2.0
244 stars 38 forks source link

Add a feature to display a prompt, then read a password #12

Closed octotep closed 8 years ago

octotep commented 8 years ago

I find myself writing code like this a lot:

print!("Please enter password: ");
io::stdout().flush().unwrap();
let password = read_password().unwrap();

It would be much nicer to instead write something like this instead:

let password = prompt_password("Please enter password: ").unwrap();

Is this a feature that rustastic-password is interested in adding? I find it very convenient and have it defined as a function in my code, but I think it would make a great addition to the library.

conradkleinespel commented 8 years ago

@octotep Sounds good ! I tend to do this as well. In fact, even the example for rpassword does this.

I'm glad to review / merge a pull request if you have the time to do one. If you do, please include a unit test for the added function as well, at least for the platform you are using rpassword on :smiley:

octotep commented 8 years ago

I was really hoping to take a crack at it last weekend, and then this weekend, but unfortunately I haven't had the time, and probably won't for the foreseeable future. Should anyone else have some time to work on it, feel free to do so.

conradkleinespel commented 8 years ago

Hi @octotep !

This took a long time but its finally here. I've added two methods that should fit the use case you were talking about (check example.rs for more details).

The link to the docs are broken but hopefully the function names are sufficiently clear.

I have found it to be very useful to print on stderr instead of stdout sometimes (for instance if you pipe the STDOUT of a command that prompts for a password, prompting on STDERR is a simple hack that allows the prompt to still show in the terminal despite the pipe), which is why I've put one function for each output stream.

Let me know what you think. I'll bump the crates.io version in a few minutes.

Conrad