Welcome to WebmasterWorld Guest from 54.145.235.72

Forum Moderators: open

JavaScript Hash Function

Looking to consistantly return the same hash for the same value

   
4:05 pm on Apr 15, 2007 (gmt 0)

5+ Year Member



I'm wondering if JavaScript has a one-way hash function that I could encode my data with that will consistantly return the same hash for the same value.

I have a random value that is automatically generated using PHP.

On my website I have an image that displays this value.

What I would like to do is to have a hidden input field in my HTML that has a hashed version of my original random value using PHP.

Then when a user types in a value into the browser, on submit I could hash the input to see if it matches the hidden hashed value, so as not to waste server requests for bad matches.

Of course I would reconfirm the match on my server side, for things like people without javascript, and I understand this would be suseptible at a lower level than other encryption, but thats fine with me.

I'm just trying to find out if there is a one-way hash capability in Javascript with consistant returns for consistant values.

Thanks.

4:13 pm on Apr 15, 2007 (gmt 0)

5+ Year Member



Hi,

Javascript doesn't have anything built in that I can think of.
You can get MD5 and SHA1 hashing functions writen in javascript here [pajhome.org.uk].

Andrew

4:46 pm on Apr 15, 2007 (gmt 0)

5+ Year Member



Thanks for the reply,

I checked out that script but it worries me a little.

It seems that script returns a consistant value for md5, whereas a PHP value for md5 has lots of different returns.

Thanks again for the reply. I think I'm going to go in a slightly different direction that will only require a tiny server request.

4:54 pm on Apr 15, 2007 (gmt 0)

5+ Year Member



Hi,

They work fine:

<?php echo md5("test");?>
<script type="text/javascript">document.write(hex_md5("test"));</script>

These both return the same thing (098f6bcd4621d373cade4e832627b4f6).

Andrew

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month