How to hide password input from terminal in ruby script

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

    There is a library called highline which works like this:

    require 'rubygems'
    require 'highline/import'
    
    password = ask("Enter password: ") { |q| q.echo = false }
    # do stuff with password
    

提交回复
热议问题