Crypt for ruby?

December 29th, 2006

Alright, fellow php-turned-rails coders… I’m working on a plugin that lets you have a php compatibility layer for all those precious functions that you can’t seem to let go of! I’m developing it on a ‘code-a-function-as-i-need-it’ basis.

One thing had me COMPLETELY discombobulated for a while though, and that is the lack of an obvious ‘crypt’ function for generating DES/MD5 encryptions suitable for system/mail passwords (not the hex_digest kind). In php, it was a simple as…

1
2
3
$string = "i should have read the docs";
$salt = "$1RbeoAkQobvI"; // make sure the length matches the type
 echo crypt($string, $salt).

It turns out, that my favorite trusty RDoc widget had the answer all along! The ruby String object has a built-in crypt method that takes a salt parameter..


p "i should have read the docs".crypt("$1RbeoAkQobvI")

I shall have my rather skimpy plugin ready for you guys next week, check back for the svn url by Jan 3rd 2006!

Leave a Reply

 

Michael Cerna Chicago-based Rails Developer and Avid Musician. More ...

Search

Categories

  • Home (15)
  • Rails Plugins (5)
  • Pages (9)
  • Archives

    Tags

    BlogRoll