[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Passwords

John Chant

1/21/2009 6:40:00 PM

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
--
Posted via http://www.ruby-....

7 Answers

Gregory Brown

1/21/2009 6:47:00 PM

0

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.ruby...

-greg

--
Technical Blaag at: http://blog.majesticseacr...
Non-tech stuff at: http://metametta.bl...
"Ruby Best Practices" Book now in O'Reilly Roughcuts:
http://rubybestpra...

Ben Bleything

1/21/2009 6:50:00 PM

0

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-pass...

It's pretty simple:

Password.get( "Your prompt: " )

Ben

John Chant

1/21/2009 7:08:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

Thanks, that is simple, but where do I find Password?, what requires do I
need?

2009/1/21 Ben Bleything <ben@bleything.net>

> 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-pass...
>
> It's pretty simple:
>
> Password.get( "Your prompt: " )
>
> Ben
>
>

Ben Bleything

1/21/2009 7:11:00 PM

0

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

Bertram Scharpf

1/22/2009 11:20:00 AM

0

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/p...

Needs the termios gem and UN*X.

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...

Saji N. Hameed

1/22/2009 11:33:00 AM

0

* 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/p...
>
> 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



Gregory Brown

1/22/2009 7:38:00 PM

0

On Thu, Jan 22, 2009 at 6:33 AM, Saji N. Hameed <saji@apcc21.net> wrote:
> * 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/p...
>>
>> 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 }