getpass

Discussion in 'Ruby' started by Yang Zhang, Apr 11, 2008.

  1. Yang Zhang

    Yang Zhang Guest

    Hi, how do I do getpass() in ruby? Thanks!
     
    Yang Zhang, Apr 11, 2008
    #1
    1. Advertising

  2. -----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-----
     
    Phillip Gawlowski, Apr 11, 2008
    #2
    1. Advertising

  3. Yang Zhang

    Yang Zhang Guest

    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


    Phillip Gawlowski wrote:
    > -----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-----
    >



    --
    Yang Zhang
    http://www.mit.edu/~y_z/
     
    Yang Zhang, Apr 11, 2008
    #3
  4. -----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-----
     
    Phillip Gawlowski, Apr 11, 2008
    #4
  5. 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 Hinegardner


    On Fri, Apr 11, 2008 at 01:08:40PM +0900, 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
    >
    >
    > Phillip Gawlowski wrote:
    >> -----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-----

    >
    >
    > --
    > Yang Zhang
    > http://www.mit.edu/~y_z/
    >
     
    Jeremy Hinegardner, Apr 11, 2008
    #5
  6. Yang Zhang

    Ken Bloom Guest

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


    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

    --
    Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory.
    Department of Computer Science. Illinois Institute of Technology.
    http://www.iit.edu/~kbloom1/
     
    Ken Bloom, Apr 13, 2008
    #6
  7. Yang Zhang

    zor Guest

    Sorry if I'm doing this wrong, but how do I get off the mailing list?
    I can't figure it out.
    On Apr 13, 2008, at 1:10 AM, Ken Bloom wrote:

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

    >
    > 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
    >
    > --
    > Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory.
    > Department of Computer Science. Illinois Institute of Technology.
    > http://www.iit.edu/~kbloom1/
    >
     
    zor, Apr 13, 2008
    #7
  8. Yang Zhang

    Todd Benson Guest

    On Sun, Apr 13, 2008 at 1:16 PM, zor <> 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
     
    Todd Benson, Apr 13, 2008
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lucas Raab

    getpass

    Lucas Raab, Oct 12, 2003, in forum: Python
    Replies:
    1
    Views:
    493
    Jorge Godoy
    Oct 12, 2003
  2. John Salerno

    why does getpass() show the input?

    John Salerno, Aug 9, 2006, in forum: Python
    Replies:
    6
    Views:
    1,830
    John Salerno
    Aug 10, 2006
  3. How to fool getpass()

    , Aug 15, 2006, in forum: C Programming
    Replies:
    2
    Views:
    370
    jmcgill
    Aug 15, 2006
  4. Andrew

    getpass and IDEs

    Andrew, Feb 25, 2011, in forum: Python
    Replies:
    3
    Views:
    525
    Nobody
    Feb 26, 2011
Loading...

Share This Page