# MD5 BSD like passwords

**URL:** <https://www.ruby-forum.com/t/md5-bsd-like-passwords/81771>\
**Category:** Ruby\
**Created:** [January 13, 2007, 2:41pm UTC](https://www.ruby-forum.com/t/md5-bsd-like-passwords/81771 "2007-01-13T14:41:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fcruxen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecae2f/32.png) [@fcruxen](https://www.ruby-forum.com/u/fcruxen)\
**Post date:** [January 13, 2007, 2:41pm UTC](https://www.ruby-forum.com/t/md5-bsd-like-passwords/81771/1 "2007-01-13T14:41:39Z")

</div>

I’m coding a “postfixadmin” using ruby, so, all the passwords are stored  
in DB using a bsd like md5 hash. Is there any simple way I could  
generate passwords like that (the same hash could be used to generate  
shadow pass?)?.

Really sorry for my lame english, and if the question is stupid, but I’m  
a real newbie to ruby.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![fcruxen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecae2f/32.png) [@fcruxen](https://www.ruby-forum.com/u/fcruxen)\
**Post date:** [January 13, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/md5-bsd-like-passwords/81771/2 "2007-01-13T18:11:36Z")

</div>

Felipe C. wrote:

> I’m coding a “postfixadmin” using ruby, so, all the passwords are stored  
> in DB using a bsd like md5 hash. Is there any simple way I could  
> generate passwords like that (the same hash could be used to generate  
> shadow pass?)?.
> 
> Really sorry for my lame english, and if the question is stupid, but I’m  
> a real newbie to ruby.
> 
> Thanks in advance.

just found out facets library, sorry for the stupid question.

---

<div class="post-metadata">

**Author:** ![fcruxen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecae2f/32.png) [@fcruxen](https://www.ruby-forum.com/u/fcruxen)\
**Post date:** [January 19, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/md5-bsd-like-passwords/81771/3 "2007-01-19T16:29:39Z")

</div>

On 1/13/07, Felipe C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m coding a “postfixadmin” using ruby, so, all the passwords are stored  
> in DB using a bsd like md5 hash. Is there any simple way I could  
> generate passwords like that (the same hash could be used to generate  
> shadow pass?)?.
> 
> Really sorry for my lame english, and if the question is stupid, but I’m  
> a real newbie to ruby.

you can generate MD5 with:  
require ‘digest/md5’  
hash = Digest::MD5.digest(data) # binary  
or hash = Digest::MD5.hexdigest(data) #hexa

---

<div class="post-metadata">

**Author:** ![fcruxen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecae2f/32.png) [@fcruxen](https://www.ruby-forum.com/u/fcruxen)\
**Post date:** [January 19, 2007, 4:55pm UTC](https://www.ruby-forum.com/t/md5-bsd-like-passwords/81771/4 "2007-01-19T16:55:55Z")

</div>

Thanks a bunch for the reply. I’ll take a good look at the documents.

F. Senault wrote:

> If you take a look at the manpage of the crypt system function (man 3  
> crypt or [crypt(3)](http://www.freebsd.org/cgi/man.cgi?query=crypt&sektion=3) ),  
> you’ll see an explanation of the hash format.
> 
> I have no idea of the portability of that function, though. For  
> instance, it doesn’t work on my Windows box, but it works well enough  
> with FreeBSD and Linux.
> 
> Fred

---

<div class="post-metadata">

**Author:** ![fcruxen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecae2f/32.png) [@fcruxen](https://www.ruby-forum.com/u/fcruxen)\
**Post date:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/md5-bsd-like-passwords/81771/5 "2007-01-19T16:30:39Z")

</div>

Le 13 janvier 2007 à 14:41, Felipe C. a écrit :

> I’m coding a “postfixadmin” using ruby, so, all the passwords are stored  
> in DB using a bsd like md5 hash. Is there any simple way I could  
> generate passwords like that (the same hash could be used to generate  
> shadow pass?)?.

If that’s really a BSD-like password (in the form $n$aaaaaaa$aa…), the  
crypt function should be able to generate it on a unix system, as long  
as you pass the entire salt ($ included) :

> > “password”.crypt(“$1$Eou1PtvJ$”)  
> > =\> “$1$Eou1PtvJ$bh2HAitLkEOwoU6Fjuh8i0”

If you take a look at the manpage of the crypt system function (man 3  
crypt or [crypt(3)](http://www.freebsd.org/cgi/man.cgi?query=crypt&sektion=3) ),  
you’ll see an explanation of the hash format.

I have no idea of the portability of that function, though. For  
instance, it doesn’t work on my Windows box, but it works well enough  
with FreeBSD and Linux.

Fred
