2017-04-02 9 views
0

내가 Node.js를위한 프롬프트 라이브러리를 사용하고 숨기지 않고이 코드가 있습니다노드 JS 프롬프트 라이브러리는 암호

// 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); 
}) 

베이직 클래스는 매우 간단합니다 :

// 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 

을 내가 가진 문제는 promp이 암호를 숨기지 않는다는 것입니다.

[email protected]이 D 시작

$ NPM 시작 : 여기에 가 출력 \ 문서 \ PROGRAMMATION \ NodeJS \ JIRA 노드하는 index.js

프롬프트 : 스프린트 ID를 입력합니다 : 156 프롬프트 : sikkache의 암호를 입력 : 하지 실제 암호 스프린트 ID : 156 기본 : c2lra2FjaGU6Tm90IHRoZSByZWFsIFBhc3N3b3Jk

보시다시피 암호는 분명합니다.

누구든지 나를 도울 수 있습니까, 정말 비밀 번호가 필요합니다.

답변

0

당신은 모듈 readline-sync 시도 할 수

은 *로 화면에 입력 된 텍스트를 숨 깁니다 hideEchoBack라는 옵션이

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 + '!'); 
+0

(나는 나, 창에 수치를 일하고 있어요 gitbash에서 작동하지 않습니다),하지만 그것은 powershell 8o에서 작동합니다 –