Forum: Ruby Passwords

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
94aec9df38fa10da88f14edc77622883?d=identicon&s=25 John Chant (johnfchant)
on 2009-01-21 19:41
Hi,

I'm new to Ruby ( one day), but not to programming (over 30 years) and I
would like some help.

I would like to be able to read a password without echoing the
characters typed. I've looked at getc but this echos the character (as a
number).

Something like the python getpass would be good.

John Chant
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2009-01-21 19:49
(Received via mailing list)
On Wed, Jan 21, 2009 at 1:39 PM, John Chant <john.chant@gmail.com>
wrote:
> Hi,
>
> I'm new to Ruby ( one day), but not to programming (over 30 years) and I
> would like some help.
>
> I would like to be able to read a password without echoing the
> characters typed. I've looked at getc but this echos the character (as a
> number).
>
> Something like the python getpass would be good.

http://highline.rubyforge.org/

-greg
90a73d9875462aaa9fab2feffafbffe7?d=identicon&s=25 Ben Bleything (Guest)
on 2009-01-21 19:52
(Received via mailing list)
On Wed, Jan 21, 2009 at 10:39 AM, John Chant <john.chant@gmail.com>
wrote:
> I would like to be able to read a password without echoing the
> characters typed. I've looked at getc but this echos the character (as a
> number).

The Ruby-Password library supports this.  Check it out:
http://www.caliban.org/ruby/ruby-password.shtml

It's pretty simple:

  Password.get( "Your prompt: " )

Ben
94aec9df38fa10da88f14edc77622883?d=identicon&s=25 John Chant (johnfchant)
on 2009-01-21 20:10
(Received via mailing list)
Thanks, that is simple, but where do I find Password?, what requires do
I
need?

2009/1/21 Ben Bleything <ben@bleything.net>
90a73d9875462aaa9fab2feffafbffe7?d=identicon&s=25 Ben Bleything (Guest)
on 2009-01-21 20:13
(Received via mailing list)
On Wed, Jan 21, 2009 at 11:08 AM, John Chant <john.chant@gmail.com>
wrote:
> Thanks, that is simple, but where do I find Password?, what requires do I
> need?

All of that information and more is available at the link I gave you.
It requires ruby-termios (which is available as a gem) and cracklib,
which should be available from your operating system's package
manager.

Ben
C06869c119472a139eb163b72040b0db?d=identicon&s=25 Bertram Scharpf (Guest)
on 2009-01-22 12:22
(Received via mailing list)
Hi,

Am Donnerstag, 22. Jan 2009, 03:39:57 +0900 schrieb John Chant:
> I would like to be able to read a password without echoing the
> characters typed. I've looked at getc but this echos the character (as a
> number).

http://bertram-scharpf.homelinux.com/src/password.rb

Needs the termios gem and UN*X.

Bertram
621080472679266b8e9b81aff4800398?d=identicon&s=25 Saji N. Hameed (Guest)
on 2009-01-22 12:35
(Received via mailing list)
* Bertram Scharpf <lists@bertram-scharpf.de> [2009-01-22 20:20:27
+0900]:

> Hi,
>
> Am Donnerstag, 22. Jan 2009, 03:39:57 +0900 schrieb John Chant:
> > I would like to be able to read a password without echoing the
> > characters typed. I've looked at getc but this echos the character (as a
> > number).
>
> http://bertram-scharpf.homelinux.com/src/password.rb
>
> Needs the termios gem and UN*X.

an alternative suggestion is ...

  def get_password
      print "Password: "
      `stty -echo`
      @pass=STDIN.gets.chomp ensure `stty echo`
  end


--
Saji N. Hameed

APEC Climate Center                  +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705      saji@apcc21.net
KOREA
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2009-01-22 20:40
(Received via mailing list)
On Thu, Jan 22, 2009 at 6:33 AM, Saji N. Hameed <saji@apcc21.net> wrote:
>>
>> Needs the termios gem and UN*X.
>
> an alternative suggestion is ...
>
>  def get_password
>      print "Password: "
>      `stty -echo`
>      @pass=STDIN.gets.chomp ensure `stty echo`
>  end

It's worth mentioning that of all the solutions recommended, Highline
is the only one that works cross-platform comfortably.

require "highline/import"

pass = ask("Enter your password:  ") { |q| q.echo = false }
This topic is locked and can not be replied to.