Getpass

Hi, how do I do getpass() in ruby? Thanks!

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

Yang Z. 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 G.
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-----

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

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

Yang Z. 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 G.
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-----

On Thu, 10 Apr 2008 23:08:40 -0500, Yang Z. 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

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 symbolgetpass’ (RuntimeError)
from /usr/lib/ruby/1.8/dl/import.rb:145:in import' from /usr/lib/ruby/1.8/dl/import.rb:61:inextern’

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

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

Jeremy H. [email protected]

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

On Sun, Apr 13, 2008 at 1:16 PM, zor [email protected] wrote:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs