MCSManager/core/User/CryptoMine.js
2017-11-13 12:26:31 +08:00

29 lines
762 B
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const crypto = require('crypto');
function md5(text) {
return crypto.createHash('md5').update(text).digest('hex');
}
function createPassword(_password, _salt) {
let PasswordMD5 = md5(_password);
PasswordMD5 = PasswordMD5 + _salt;
PasswordMD5 = md5(PasswordMD5);
return {
password: PasswordMD5,
salt: _salt
}
}
function randomString(len) {  
len = len || 32;  
var $chars = 'ABCDEFGHIJKLNMOPQRSTUVWXYZabcdefghijklnmopqrstuvwxyz1234567890';
var maxPos = $chars.length;  
var pwd = '';  
for (i = 0; i < len; i++) {    
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));  
}  
return pwd;
}
module.exports = { md5, createPassword, randomString }