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

inconsistent behavior on Windows #32

Closed JMLX42 closed 5 years ago

JMLX42 commented 5 years ago

Hi,

I'm using rpassword in a cross-platform CLI app.

I have an issue on Windows: after pressing "enter" to validate the password, there is no new line added to the terminal.

image

The behavior is different on Llinux:

image (5)

Here is my code:

trace!("prompt for passphrase");
let pass_string = rpassword::prompt_password_stderr(passphrase_prompt.as_str())
    .unwrap();

trace!("passphrase fetched from command line");

Am I doing something wrong?

conradkleinespel commented 5 years ago

@promethe42 Hello and thanks for your question. I do not use Windows and thus do not really know how well the crate works on Windows. Unfortunately, I do not have time to invest in testing the crate properly for Windows at the current time.

If @equalsraf or @retep998 happen to have time, they may be able to help.

If you work out the problem, I'm happy to review/test/merge a PR.

retep998 commented 5 years ago

This crate disables ENABLE_ECHO_INPUT so that the password is not printed to the console, but this also prevents the enter key from being printed resulting in no newline. You'd have to manually print out a newline after inputting the password.

JMLX42 commented 5 years ago

This crate disables ENABLE_ECHO_INPUT so that the password is not printed to the console, but this also prevents the enter key from being printed resulting in no newline.

Not on Linux. Which is kinda the whole issue here. I expect the behavior to be the same on both platforms and not have to do this kind of dirty tricks:

https://github.com/aerys/gpm/blob/master/src/gpm/ssh.rs#L183

retep998 commented 5 years ago

By "you" I meant rpassword, so rpassword would have to manually print out the newline on Windows.

conradkleinespel commented 5 years ago

@promethe42 Would you be open to opening a pull request for this change ?

conradkleinespel commented 5 years ago

@retep998 Thanks for your help ! :+1:

JMLX42 commented 5 years ago

@conradkdotcom any hint as of where is the code I should fix? Any help appreciated.

conradkleinespel commented 5 years ago

@promethe42 Sure ! You could probably print a newline on line 225 of lib.rs: https://github.com/conradkdotcom/rpassword/blob/master/src/lib.rs#L225

conradkleinespel commented 5 years ago

@promethe42 Give it a try and let me know if it works out :slightly_smiling_face:

joshuef commented 5 years ago

Just came across this as we were having a similar issue (using two rpassword inputs one after another).

https://github.com/conradkdotcom/rpassword/pull/33

Implements the fix you suggested @conradkdotcom, and we tested it on windows/osx and it's looking good 👍

conradkleinespel commented 5 years ago

Awesome, thanks @joshuef !