Forum: Ruby How to check user name and password for Linux accounts

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.
Zhao Y. (Guest)
on 2009-01-08 05:41
Can ruby check user name and password the same way as Linux OS? I use
"ypcat passwd" to list all users and its encrypted password. I want
users to input their user name and password to ruby and let ruby the
check its validation.

thanks.
Roger P. (Guest)
on 2009-01-08 08:23
Zhao Yi wrote:
> Can ruby check user name and password the same way as Linux OS? I use
> "ypcat passwd" to list all users and its encrypted password. I want
> users to input their user name and password to ruby and let ruby the
> check its validation.
>
> thanks.

You may be able to find a wrapper to crypt(3) or whatever your system
uses to generate the hashes in the passwd file.  Or a pure ruby one.
-=r
Matt H. (Guest)
on 2009-01-08 09:11
(Received via mailing list)
Zhao Yi wrote:
> Can ruby check user name and password the same way as Linux OS? I use
> "ypcat passwd" to list all users and its encrypted password. I want
> users to input their user name and password to ruby and let ruby the
> check its validation.
>
> thanks.

If your system uses PAM, like most modern linux distros, you might want
to look at Ruby/PAM[1]

I haven't tried it but a quick look through the examples seems like it
could work for you.

[1]http://ruby-pam.sourceforge.net/pam-ruby.html

HTH

Matt
Brian C. (Guest)
on 2009-01-08 11:47
If you have the encrypted passwords from ypcat, then they are easy to
check.

irb(main):002:0> enc_pw = "aauZSSiXB7FbU"
=> "aauZSSiXB7FbU"
irb(main):003:0> "ruby".crypt(enc_pw) == enc_pw
=> true

irb(main):005:0> enc_pw = "$1$aaaa$jM9byC6tzuk.OYACuTQrJ/"
=> "$1$aaaa$jM9byC6tzuk.OYACuTQrJ/"
irb(main):006:0> "ruby".crypt(enc_pw) == enc_pw
=> true
This topic is locked and can not be replied to.