1

I'm trying to figure out if it's possible to convert the following MD5 conversion of a password and challenge from a method in my Rails application into jQuery. So far, I've failed at every hurdle.

Basically, I'm trying to take a username / password / challenge from a form and submit it to an external url.

It works in our Rails application but we need to post via ajax / jquery.

 def my_method
    hex_chal = Array[params['challenge']].pack('H32')
    newchal = Array[Digest::MD5.hexdigest(hex_chal + secret)].pack('H*')
    response = Digest::MD5.hexdigest("\0" + params['password'] + newchal)
    new_pwd = Array[params['password']].pack('a32') 
 end

Using the jquery md5 library, I have tried something like this:

function Test() {
  ...
  var hex_chal = $.md5(params('challenge'));
  var new_chal = $.md5(hex_chal + params('password'));
  ...
}

No idea if this is possible. If it's not, I'll have to find another way to do it.

simonmorley
  • 2,810
  • 4
  • 30
  • 61
  • 1
    You mean, you want to convert it to *JavaScript*; jQuery is merely a tool - See http://stackoverflow.com/questions/1655769/fastest-md5-implementation-in-javascript – Sampson Dec 19 '12 at 20:41
  • Password comparison is generally not performed client-side as it is too easy to defeat. Therefore a javascript implementation of MD5 is not generally needed. However, if you really want one, I'm sure you will find a js implementation somewhere on the web. That will be much easier than translating from another language. – Beetroot-Beetroot Dec 19 '12 at 20:45
  • @beetroot-beetroot. Thanks. That's what I needed to know. Can you put that in an answer and I'll accept it. Need to go the other way. S – simonmorley Dec 19 '12 at 21:16

1 Answers1

2

Simon,

Password comparison is generally not performed client-side as it is too easy to defeat. Therefore a javascript implementation of MD5 is not generally needed.

However, if you really want one, I'm sure you will find a js implementation somewhere on the web. That will be much easier than translating from another language.

(-: Beetroot :-)

Beetroot-Beetroot
  • 18,022
  • 3
  • 37
  • 44