How to hide password input from terminal in ruby script

前端 未结 6 1764
囚心锁ツ
囚心锁ツ 2020-11-30 20:50

I am new to ruby. I need to receive password as an input through gets command.

How do I hide the password input typed in the terminal, during gets

6条回答
  •  有刺的猬
    2020-11-30 21:21

    Best method from @eclectic923's answer:

    require 'io/console'
    password = STDIN.noecho(&:gets).chomp
    

    For 1.9.3 (and above), this requires you adding require 'io/console' to your code.

    Original Answer:

    Ruby "Password" is another alternative.

提交回复
热议问题