homepage Welcome to WebmasterWorld Guest from 54.242.231.109
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JavaScript Hash Function
Looking to consistantly return the same hash for the same value
otem




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

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.

 

Little_G




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

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

otem




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

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.

Little_G




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved