# How to check user name and password for Linux accounts

**URL:** <https://www.ruby-forum.com/t/how-to-check-user-name-and-password-for-linux-accounts/157175>\
**Category:** Ruby\
**Created:** [January 8, 2009, 4:41am UTC](https://www.ruby-forum.com/t/how-to-check-user-name-and-password-for-linux-accounts/157175 "2009-01-08T04:41:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [January 8, 2009, 4:41am UTC](https://www.ruby-forum.com/t/how-to-check-user-name-and-password-for-linux-accounts/157175/1 "2009-01-08T04:41:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [January 8, 2009, 7:23am UTC](https://www.ruby-forum.com/t/how-to-check-user-name-and-password-for-linux-accounts/157175/2 "2009-01-08T07:23:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [January 8, 2009, 10:47am UTC](https://www.ruby-forum.com/t/how-to-check-user-name-and-password-for-linux-accounts/157175/3 "2009-01-08T10:47:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [January 8, 2009, 8:11am UTC](https://www.ruby-forum.com/t/how-to-check-user-name-and-password-for-linux-accounts/157175/4 "2009-01-08T08:11:12Z")

</div>

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][PAM/Ruby](http://ruby-pam.sourceforge.net/pam-ruby.html)

HTH

Matt
