primitive.tools-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-21 15:50 UTC
Ruby/Rails String to Unicode conversion...
Hello everyone, I am working on my first professional programming project, and so far it''s been pretty good, but I have a small problem. The project is being developed in Ruby on Rails, but involves dealing with a legacy database full of old usernames/passwords which are still being used. The passwords are encrypted via some hashing method, but for internationalization purposes, they are first converted to Unicode strings before being hashed. This is the part that is not working - the hashed String password and hashed Unicode password are totally different. I''ve been thinking about it and just can''t figure how to turn a standard ::String into a Unicode string. Any help or insights would really really really be appreciated! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
primitive.tools-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Hello everyone, > I am working on my first professional programming project, and so far > it''s been pretty good, but I have a small problem. The project is > being developed in Ruby on Rails, but involves dealing with a legacy > database full of old usernames/passwords which are still being used. > The passwords are encrypted via some hashing method, but for > internationalization purposes, they are first converted to Unicode > strings before being hashed. This is the part that is not working - > the hashed String password and hashed Unicode password are totally > different. I''ve been thinking about it and just can''t figure how to > turn a standard ::String into a Unicode string. Any help or insights > would really really really be appreciated!"Unicode" is not a format. Rails strings are UTF-8, which is a particular unicode encoding. You need to know which unicode encoding your target strings are in. Once you know that, you need to look at Iconv. It''s part of the Ruby standard library set. Pete Yandell http://notahat.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can use Iconv. perhaps those two methods I use might help you ? you can change the encoding to get what you want, eg. unicode string as UTF-16 def to_iso8859_1(value) Iconv.iconv(''ISO-8859-1'',''UTF-8'', value).join end def to_utf_8(value) Iconv.iconv(''UTF-8'',''ISO-8859-1'', value).join end primitive.tools-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org schrieb:> Hello everyone, > I am working on my first professional programming project, and so far > it''s been pretty good, but I have a small problem. The project is > being developed in Ruby on Rails, but involves dealing with a legacy > database full of old usernames/passwords which are still being used. > The passwords are encrypted via some hashing method, but for > internationalization purposes, they are first converted to Unicode > strings before being hashed. This is the part that is not working - > the hashed String password and hashed Unicode password are totally > different. I''ve been thinking about it and just can''t figure how to > turn a standard ::String into a Unicode string. Any help or insights > would really really really be appreciated!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---