Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. var readline = require('readline');
  2.  
  3. var rl = readline.createInterface({
  4. input: process.stdin,
  5. output: process.stdout
  6. });
  7.  
  8. rl.question("password : ", function(password) {
  9. console.log("Your password : " + password);
  10. });
  11.  
  12. var readline = require('readline');
  13. var Writable = require('stream').Writable;
  14.  
  15. var mutableStdout = new Writable({
  16. write: function(chunk, encoding, callback) {
  17. if (!this.muted)
  18. process.stdout.write(chunk, encoding);
  19. callback();
  20. }
  21. });
  22.  
  23. mutableStdout.muted = false;
  24.  
  25. var rl = readline.createInterface({
  26. input: process.stdin,
  27. output: mutableStdout,
  28. terminal: true
  29. });
  30.  
  31. rl.question('Password: ', function(password) {
  32. console.log('nPassword is ' + password);
  33. rl.close();
  34. });
  35.  
  36. mutableStdout.muted = true;
  37.  
  38. password : [-=]
  39. password : [=-]
  40.  
  41. var readline = require('readline');
  42.  
  43. var rl = readline.createInterface({
  44. input: process.stdin,
  45. output: process.stdout
  46. });
  47.  
  48. function hidden(query, callback) {
  49. var stdin = process.openStdin(),
  50. i = 0;
  51. process.stdin.on("data", function(char) {
  52. char = char + "";
  53. switch (char) {
  54. case "n":
  55. case "r":
  56. case "u0004":
  57. stdin.pause();
  58. break;
  59. default:
  60. process.stdout.write("33[2K33[200D"+query+"["+((i%2==1)?"=-":"-=")+"]");
  61. i++;
  62. break;
  63. }
  64. });
  65.  
  66. rl.question(query, function(value) {
  67. rl.history = rl.history.slice(1);
  68. callback(value);
  69. });
  70. }
  71.  
  72. hidden("password : ", function(password) {
  73. console.log("Your password : " + password);
  74. });
  75.  
  76. var readline = require('readline');
  77.  
  78. var rl = readline.createInterface({
  79. input: process.stdin,
  80. output: process.stdout
  81. });
  82.  
  83. function hidden(query, callback) {
  84. var stdin = process.openStdin();
  85. process.stdin.on("data", function(char) {
  86. char = char + "";
  87. switch (char) {
  88. case "n":
  89. case "r":
  90. case "u0004":
  91. stdin.pause();
  92. break;
  93. default:
  94. process.stdout.write("33[2K33[200D" + query + Array(rl.line.length+1).join("*"));
  95. break;
  96. }
  97. });
  98.  
  99. rl.question(query, function(value) {
  100. rl.history = rl.history.slice(1);
  101. callback(value);
  102. });
  103. }
  104.  
  105. hidden("password : ", function(password) {
  106. console.log("Your password : " + password);
  107. });
  108.  
  109. function hidden(query, callback) {
  110. var stdin = process.openStdin();
  111. var onDataHandler = function(char) {
  112. char = char + "";
  113. switch (char) {
  114. case "n": case "r": case "u0004":
  115. // Remove this handler
  116. stdin.removeListener("data",onDataHandler);
  117. break;//stdin.pause(); break;
  118. default:
  119. process.stdout.write("33[2K33[200D" + query + Array(rl.line.length+1).join("*"));
  120. break;
  121. }
  122. }
  123. process.stdin.on("data", onDataHandler);
  124.  
  125. rl.question(query, function(value) {
  126. rl.history = rl.history.slice(1);
  127. callback(value);
  128. });
  129. }
  130.  
  131. let read_Line_Str = "";
  132. let credentials_Obj = {};
  133. process.stdin.setEncoding('utf8');
  134. process.stdin.setRawMode( true );
  135. process.stdout.write( "Enter password:" );
  136. process.stdin.on( 'readable', () => {
  137. const chunk = process.stdin.read();
  138. if ( chunk !== null ) {
  139. read_Line_Str += chunk;
  140. if(
  141. chunk == "n" ||
  142. chunk == "r" ||
  143. chunk == "u0004"
  144. ){
  145. process.stdout.write( "n" );
  146. process.stdin.setRawMode( false );
  147. process.stdin.emit('end'); /// <- this invokes on.end
  148. }else{
  149. // providing visual feedback
  150. process.stdout.write( "*" );
  151. }
  152. }else{
  153. //console.log( "readable data chunk is null|empty" );
  154. }
  155. } );
  156. process.stdin.on( 'end', () => {
  157. credentials_Obj.user = process.env.USER;
  158. credentials_Obj.host = 'localhost';
  159. credentials_Obj.database = process.env.USER;
  160. credentials_Obj.password = read_Line_Str.trim();
  161. credentials_Obj.port = 5432;
  162. //
  163. connect_To_DB( credentials_Obj );
  164. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement