Adding a hash method to underscore.string.js #247

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet
2 participants
@svub

svub commented Dec 8, 2013

A hash method for underscore.string.js

I needed a string-to-hash method for my current project to create keys for strings and to add a simple password check without transferring the password as plain text to the server. I think this hash method for strings fits perfectly with underscore.string - actually, I was a bit surprised that it did not exist already, neither here nor in underscore.js.

About the added method:

_s.hash(str) returns a number unique for the given string. The method is the same as implemented in Java and thus a kind of standard. It can be used for creating IDs; avoiding plain text when checking or transferring passwords or for caching. The implementation has been chosen according to http://jsperf.com/hashing-strings/22 (the one with the highest performance on the majority of browsers).

Added "hash(str)" method to underscore.string.js
_s.hash(str) returns a number unique for the given string. The method is the same as implemented in Java and thus a kind of standard. It can be used for creating IDs; avoiding plain text when checking or transferring passwords.
Chose implementation with highest performance according to http://jsperf.com/hashing-strings/22
@epeli

This comment has been minimized.

Show comment
Hide comment
@epeli

epeli Dec 11, 2013

Owner

Why not just use sha1 or md5?

Owner

epeli commented Dec 11, 2013

Why not just use sha1 or md5?

@svub

This comment has been minimized.

Show comment
Hide comment
@svub

svub Dec 11, 2013

Hmmm, I do not really care what method is used internally - what ever is more efficient. But the suggested one is compatible with Java. I did not check if the Java way produces the same result as sha1 or md5, though. But i agree that it is a good idea to stick with standards like sha1 and md5. Nevertheless, it would be nice and handy to have this kind of method to be part of underscore.string.js. :)

svub commented Dec 11, 2013

Hmmm, I do not really care what method is used internally - what ever is more efficient. But the suggested one is compatible with Java. I did not check if the Java way produces the same result as sha1 or md5, though. But i agree that it is a good idea to stick with standards like sha1 and md5. Nevertheless, it would be nice and handy to have this kind of method to be part of underscore.string.js. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment