0

I want to make a website that takes plain text and hashing it into md5 hash, I don't know how websites implement those things, and how can I access this library ?

const md5 = require('crypto');
  • Hello and Welcome, I mean you want to store into a database the hashed or encrypted password a user store when by example is creating a username and password? – Hasan Patel Jul 19 '20 at 17:45
  • @HasanPatel Hi. No, I don't want to create a database. I want to know how to access the `crypto` library when not using `nodejs` or something else. Access it functions in my website. –  Jul 19 '20 at 17:47
  • Does this help? https://stackoverflow.com/questions/1655769/fastest-md5-implementation-in-javascript – schteppe Jul 19 '20 at 17:52
  • I think this is what you are looking for; https://stackoverflow.com/questions/51005488/how-to-use-cryptojs-in-javascript/51005584 – Hasan Patel Jul 19 '20 at 18:02

1 Answers1

0

CryptoJS is a growing collection of standard and secure cryptographic algorithms implemented in JavaScript using best practices and patterns. They are fast, and they have a consistent and simple interface.

This is a way to call it without nodejs using the scripts, better to use the full cryptojs library.

var plaintext   = "Hello World";
var encriptedtext = CryptoJS.MD5(plaintext)
document.getElementById("md5").innerHTML = encriptedtext
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js"></script>

<span id="md5">MD5: </span>

You need an Encoder to convert from encoding formats to WordArray objects and vica versa Example:

CryptoJS.enc.Utf8

Now it is valid to point out MD5 is kind outdated and not recomended to store passwords and it is better to use SHA please review this link: MD5 vs SHA

Hasan Patel
  • 412
  • 7
  • 19
  • Thanks. But why would you use `var` instead of `let` ? I heard that `var` is an **oldschool** way and we should use `let` instead. –  Jul 19 '20 at 19:03
  • let works very much like var. The main difference is that the scope of a var variable is the entire enclosing function [Using let and var what's the difference?](https://stackoverflow.com/questions/762011/whats-the-difference-between-using-let-and-var) – Hasan Patel Jul 19 '20 at 19:10