md5
is an hashing method, not an encryption method. It is a common algorithm that could be implemented in any language, so I'm sure a JavaScript version exists out there.
However, your logic is flawed. Why do you want to hash the password on the client side? Then the hashed password can be captured en route to the server, which is even worse than if the server hashed it alone. This offers no protection whatsoever.
On a related note, md5
is a very insecure hash. Use bcrypt
.
The difference between hashing vs. encryption is that the former creates a digest whereas the latter creates encrypted content that can be decrypted. A hash digest cannot be converted back to the original data because it is lost (on purpose). Hashing is used for authentication, encryption for secrecy.
To expand on the fact that client-side hashing is at most as effective as server-side hashing, think about the fact that authentication is done when the hash digest is compared to the value stored in the DB.
The value that you store is the md5
of the original password. To authenticate, you have to receive the password, use md5
, and then compare it to the digest in the DB. This means md5
must be called at most one time. If you want to call it in JS, then it will not be called in php. This means that if someone intercepts the md5
it's just as effective as if they intercepted the original password because they can just post the md5
to your server and no additional hashing is done.
If you also did an md5
hash on the server side, that wouldn't make any difference because the same unhashed value (relative to the PHP operation) is received. In point of fact, it is less secure because repeating the same hash increases the probability of a collision.