Created
March 7, 2013 02:25
-
-
Save adam-singer/5105108 to your computer and use it in GitHub Desktop.
Example of how to prompt for password in dart console using streams. Not exactly secure since echo is not disabled. Taken from the dart-gde discovery project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* $ cat /Applications/dart/dart-sdk/version | |
* 0.4.1.0_r19425 | |
*/ | |
import "dart:io"; | |
import "dart:uri"; | |
import "dart:async"; | |
Future<String> promptPassword() { | |
var completer = new Completer<String>(); | |
StreamSubscription stdinSubscription; | |
stdout.addString("enter password: "); | |
readLine(String line) { | |
stdout.addString("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); | |
stdinSubscription.cancel(); | |
completer.complete(line); | |
}; | |
stdinSubscription = stdin | |
.transform(new StringDecoder()) | |
.transform(new LineTransformer()) | |
.listen(readLine); | |
return completer.future; | |
} | |
void main() { | |
promptPassword().then((password)=>print("password = $password")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment