我gem gmail
在一个项目中使用终端登录帐户;操作系统是linux(debian whezzy)。
以下是运行代码的示例:
user@linux:/home/user/project$ ruby --version
**ruby 2.1.0p0 (2013-12-25 revision 44422) [i686-linux]**
user@linux:/home/user/project$ ruby login.rb
===========
Gmail login
===========
please give your username (without @gmail.com) and password
(they will not be show, so please type first, press RET, type password)
username: # waiting for username...
password: # waiting for password...
问题是:使用gets.chomp
,提示符将显示它的用户名/密码字符串。我不要这个 我希望有一个类似于UNIX系统帐户登录的功能,即提示等待输入,但不将其显示为用户键入的内容。
4一些参考,我把使用的代码:
def respond_to(&block)
puts "==========="
puts "Gmail login"
puts "==========="
puts "please give your username (without @gmail.com) and password (they will not be show, so please type first, press RET, type password)"
Gmail.connect("#{gets.chomp}@gmail.com", "#{gets.chomp}") do |client|
if client.logged_in?
puts "\n#{client.username} sucessfully logged in!\n"
yield(false, client)
else
true
end
end
end
我遵循了zetcode中的一些技巧,但是没有光线。
谢谢!
有一些宝石可以满足您的需求-其中之一是password
:
Ruby / Password是Ruby的密码处理例程的集合,其中包括一个用于测试密码强度的CrackLib接口。
require 'password' # Define and check a password in code pw = Password.new( "bigblackcat" ) pw.check # Get and check a password from the keyboard begin password = Password.get( "New password: " ) password.check rescue Password::WeakPassword => reason puts reason retry end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句