In the actual work development, no one will directly put the password in the database. Because this practice is very unsafe, it is usually encrypted with MD5! For example, a user's password is "123456" (of course, such a password has no security at all), and it is handled by MD5:
E10 ADC 3949ba59abbe56E057F20F883e. The benefits of this mainly include the following two points:
1, to prevent website operators from knowing your password and making some immoral behaviors. Because many people set all passwords the same for convenience.
2, to prevent external attacks, if your registered website is hacked, get some data of the website and get a string of strings processed by MD5.
Note: MD5 generally cannot be decompiled. Provided that your password is not too simple. This is why more and more websites now require users to set passwords more and more. Not only is the password long enough, but it also includes numbers, letters and special strings.
This paper will mainly study how to encrypt the data in the node by MD5. JS:
The md5 dependency package is directly introduced into the node;
Download and install the md5 dependency package.
Npm installation md5
Md5 encryption instance:
var MD5 = require(" MD5 ");
//Set the encryption string
Varpassword = "if (1=1) {console.log ('I love you')}";
Console.log(md5 (password)); //a 775657889 f 1 ad6e 19 178 C3 CD 734392 b
Of course, it is not safe to simply encrypt data with MD5. It's best to add some salt to the data:
var MD5 = require(" MD5 ");
//Set the encryption string
Varpassword = "if (1=1) {console.log ('I love you')}";
//Add some special words to the original string, such as "zhangpeiyue.com".
Console.log(md5 (password+"zhangpeiyue.com")); // 13c 22698 f 52329433 107 e75b 49330484
MD5 encryption mode in nodejs:
The first kind:
var crypto = require(' crypto ');
var MD5 = crypto . create hash(" MD5 ");
MD5 . update(" abcdef ");
var str = MD5 . digest(' hex ');
var s = str . toupper case(); //32-bit uppercase
console.log
The second type:
var md5=require("md5 ")
var str=md5("abcdef ")
//str = E80b5017098950fc58aad83c8c14978e defaults to 32-bit lowercase.