getpass

P

Phillip Gawlowski

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yang Zhang wrote:
| Hi, how do I do getpass() in ruby? Thanks!

def getpass
~ "do getpass()"
end

Please elaborate on what you mean, and want to do.

- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan

Use data arrays to avoid repetitive control sequences.
~ - The Elements of Programming Style (Kernighan & Plaugher)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkf+1i0ACgkQbtAgaoJTgL870wCeMdCUU+JnWgaWkq1Xx6tqHraN
j6kAnjXLAWKYupSM/Z/65oWPvZp+z0AU
=blU3
-----END PGP SIGNATURE-----
 
P

Phillip Gawlowski

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yang Zhang wrote:
| Thanks for prompting me to provide some context. getpass() is a
| standard POSIX function, described here:
|
| http://www.opengroup.org/pubs/online/7908799/xsh/getpass.html

In that case, you'll need a C extension.

RubyInline is one library that provides that functionality (I assume
portability to non-UNICES is not really a concern ;).

Here are some presentations to using C with Ruby from Ruby conferences:

http://rubyhoedown2007.confreaks.com/session08.html
http://rubyconf2007.confreaks.com/d1t1p6_avoiding_pitfalls_in_c_extensions.html

- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan

~ - You know you've been hacking too long when...
...you send E-mail and end each line with \n.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkf+5jcACgkQbtAgaoJTgL/0BACdG40D0Q4eI1CgMkXfBmmn92aC
XYwAnAlRdaxQzIJAnV9Visz4MRhPzvTK
=2K16
-----END PGP SIGNATURE-----
 
J

Jeremy Hinegardner

Its not the getpass method, but has the same affect using Highline
http://highline.rubyforge.org/

% cat password.rb
require "rubygems"
require "highline/import"

pass = ask("Enter your password: ") { |q| q.echo = false }
puts "Your password is [#{pass}]"

pass = ask("Enter your password: ") { |q| q.echo = '*' }
puts "Your password is '#{pass}'"


% ruby password.rb
Enter your password:
Your password is [iloveruby]
Enter your password: ***********
Your password is 'i love ruby'

enjoy,

-jeremy
 
K

Ken Bloom

Thanks for prompting me to provide some context. getpass() is a
standard POSIX function, described here:

http://www.opengroup.org/pubs/online/7908799/xsh/getpass.html

getpass() is not a POSIX anything.

From the manpage:

DESCRIPTION
This function is obsolete. Do not use it.
....
CONFORMING TO
Present in SUSv2, but marked LEGACY. Removed in POSIX.1-2001.

In theory, using Ruby/DL should work, like

require 'dl/import'
module LibC
extend DL::Importable
dlload 'libc.so.6'
extern 'char *getpass( const char * prompt )'
end

In theory, theory and practice are the same.

/usr/lib/ruby/1.8/dl/import.rb:126:in `symbol': can't find the symbol
`getpass' (RuntimeError)
from /usr/lib/ruby/1.8/dl/import.rb:145:in `import'
from /usr/lib/ruby/1.8/dl/import.rb:61:in `extern'


But this works:

require 'dl'
module LibC
extend self
LIB=DL.dlopen('libc.so.6')
SYMS={ :getpass => LIB['getpass','SS'] }
def getpass prompt
r,rs = SYMS[:getpass].call prompt
return r
end
end

Again, don't use this. Use Highline instead.

--Ken
 
Z

zor

Sorry if I'm doing this wrong, but how do I get off the mailing list?
I can't figure it out.
Thanks for prompting me to provide some context. getpass() is a
standard POSIX function, described here:

http://www.opengroup.org/pubs/online/7908799/xsh/getpass.html

getpass() is not a POSIX anything.

From the manpage:

DESCRIPTION
This function is obsolete. Do not use it.
...
CONFORMING TO
Present in SUSv2, but marked LEGACY. Removed in POSIX.1-2001.

In theory, using Ruby/DL should work, like

require 'dl/import'
module LibC
extend DL::Importable
dlload 'libc.so.6'
extern 'char *getpass( const char * prompt )'
end

In theory, theory and practice are the same.

/usr/lib/ruby/1.8/dl/import.rb:126:in `symbol': can't find the symbol
`getpass' (RuntimeError)
from /usr/lib/ruby/1.8/dl/import.rb:145:in `import'
from /usr/lib/ruby/1.8/dl/import.rb:61:in `extern'


But this works:

require 'dl'
module LibC
extend self
LIB=DL.dlopen('libc.so.6')
SYMS={ :getpass => LIB['getpass','SS'] }
def getpass prompt
r,rs = SYMS[:getpass].call prompt
return r
end
end

Again, don't use this. Use Highline instead.

--Ken
 
T

Todd Benson

Sorry if I'm doing this wrong, but how do I get off the mailing list? I
can't figure it out.

From http://www2.ruby-lang.org/en/20020104.html ...

"To unsubscribe from a list, send a mail which body is "unsubscribe"
to the controller address."

The controller address is ruby-talk-ctl on the ruby-lang.org domain.

I still haven't figured out why so many people get this wrong.

Todd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,232
Latest member
DorotheaDo

Latest Threads

Top