I'm using the prompt library for Node.js and I have this code:
// Entry point for the program
var prompt =require ('prompt' )
var Basic = require('./helper/basic')
var program = require('./helper/cli-args')
var pwd = new Basic()
var promptSchema = {
properties: {
sprintID: {
description: "Enter sprint ID",
type: 'integer'
},
password: {
description: "Enter the password for " + program.user,
hidden: true
}
}
}
prompt.start()
prompt.get(promptSchema, function (err,result) {
if (err) console.log(err)
program.sprint = result.sprintID
pwd.setDigest(result.password)
prompt.stop()
console.log ("Sprint ID: ", program.sprint)
console.log("Basic: ", pwd.digest);
})
The Basic class is very simple :
// Basic authentication
var base64 = require('base-64')
var program = require ('../helper/cli-args')
class Basic {
setDigest(pwd) {
this.digest = base64.encode(program.user.concat(":").concat(pwd))
}
}
module.exports = Basic
The problem I have is that the promp doesn't hide the password. Here is an output:
$ npm start
jira@1.0.0 start D:\Documents\Programmation\NodeJS\jira node index.js
prompt: Enter sprint ID: 156 prompt: Enter the password for sikkache: Not the real Password Sprint ID: 156 Basic: c2lra2FjaGU6Tm90IHRoZSByZWFsIFBhc3N3b3Jk
As you can see, the password is clear.
Can anyone help me, I really need the password to be hidden.
you can try readline-sync module
it has an option called hideEchoBack which hides typed text on screen with *
var readlineSync = require('readline-sync');
// Wait for user's response.
var userName = readlineSync.question('May I have your name? ');
console.log('Hi ' + userName + '!');
// Handle the secret text (e.g. password).
var favFood = readlineSync.question('What is your favorite food? ', {
hideEchoBack: true // The typed text on screen is hidden by `*` (default).
});
console.log('Oh, ' + userName + ' loves ' + favFood + '!');