The example below will read in a user's password but also echo it in plain text, is there a way around this?
Future<String> promptPassword() {
var completer = new Completer<String>();
var stream = new StringInputStream(stdin);
stdout.writeString("Warning: Password will be displayed here until I find a better way to do this.\n");
stdout.writeString("Watch your back...\n");
stdout.writeString("GitHub password for $gituser: ");
stream.onLine = () {
var str = stream.readLine();
stdin.close();
completer.complete(str);
};
return completer.future;
}
This has been implemented now.
See Stdin.echoMode
import 'dart:io';
void main() {
print('Enter password: ');
stdin.echoMode = false;
var password = stdin.readLineSync();
// Do something with password...
}
This is not possible until tty control is added to dart:io. In the meantime, I recommend:
stty -echo
dart ./password.dart
stty echo
I have opened a bug here: https://code.google.com/p/dart/issues/detail?id=8190
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With