tags:

views:

404

answers:

2
+1  A: 

You'd need something like this

require 'digest/md5'
Digest::MD5.hexdigest(password.encode("UTF-8"))
Veger
+4  A: 

Maybe all you need is Digest::MD5 which will produce hexdigests of any string you give it. While Ruby 1.8 is somewhat subtle in its distinction between ISO-Latin1 and UTF-8 character sets, Ruby 1.9 provides much more control here, including conversion. If the string is supplied as UTF8, though, Ruby 1.8 generally leaves it alone, treating it as a simple byte stream.

require 'digest/md5'

def encode_password(password)
  Digest::MD5.hexdigest(password).upcase
end

# Example:
puts encode_password('foo bar')
# => "327B6F07435811239BC47E1544353273"
tadman
The problem is that when i tried this before posting here i was testing in an .rb file that output in command prompt something like this: ▄9I║Y½╛VαW≥☼ê>.Then i used <%= .. %> and the output is ok.
daniel
There's a difference between Digest::MD5.hexdigest and Digest::MD5.digest, where the former is a hexadecimal string and the latter is the raw binary equivalent.
tadman