How to hide password input from terminal in ruby script

前端 未结 6 1786
囚心锁ツ
囚心锁ツ 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:07

    Starting from Ruby version 2.3.0 you can use the IO#getpass method like this:

    require 'io/console'
    password = STDIN.getpass("Password:")
    

    See the getpass method in the Standard Library Documentation.

提交回复
热议问题