You'd need something like this
require 'digest/md5'
Digest::MD5.hexdigest(password.encode("UTF-8"))
Veger
2010-01-13 15:53:20
You'd need something like this
require 'digest/md5'
Digest::MD5.hexdigest(password.encode("UTF-8"))
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"