diff --git a/lib/server/config.js b/lib/server/config.js index 16a6040f..41ab9753 100644 --- a/lib/server/config.js +++ b/lib/server/config.js @@ -73,6 +73,8 @@ if (!is) { socket.emit('err', 'Error: Wrong data type!'); } else { + cryptoPass(json); + Object.keys(json).forEach(function(name) { data = CloudFunc.formatMsg('config', name); set(name, json[name]); @@ -132,17 +134,12 @@ pipe.getBody(req, function(error, body) { var data = '', - json = Util.json.parse(body) || {}, - passwd = json.password, - sha = crypto.createHash('sha512WithRSAEncryption'); + json = Util.json.parse(body) || {}; - if (error) { + if (error) callback(error); - } else if (passwd) { - sha.update(passwd); - passwd = sha.digest('hex'); - json.password = passwd; - } + else + cryptoPass(json); Object.keys(json).forEach(function(name) { data = CloudFunc.formatMsg('config', name); @@ -158,4 +155,19 @@ }); } + function cryptoPass(json) { + if (json && json.password) + json.password = crypt(json.password); + } + + function crypt(password) { + var result, + sha = crypto.createHash('sha512WithRSAEncryption'); + + sha.update(password); + result = sha.digest('hex'); + + return result; + } + })();