Skip to content

Commit f8a1395

Browse files
authored
Merge pull request #713 from melihkorkmaz/password-hash-argon2
Converted member password to Argon2 hashing algorithm.
2 parents 2cf3287 + 349de71 commit f8a1395

File tree

4 files changed

+179
-88
lines changed

4 files changed

+179
-88
lines changed

api/parts/mgmt/users.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ usersApi.createUser = function(params) {
234234
/**
235235
* Creates user document with hashed password
236236
**/
237-
function createUser() {
237+
async function createUser() {
238238
var passwordNoHash = newMember.password;
239-
newMember.password = common.sha512Hash(newMember.password);
239+
newMember.password = await common.argon2Hash(newMember.password);
240240
newMember.password_changed = 0;
241241
newMember.created_at = Math.floor(((new Date()).getTime()) / 1000); //TODO: Check if UTC
242242
newMember.admin_of = newMember.admin_of || [];
@@ -275,7 +275,7 @@ usersApi.createUser = function(params) {
275275
* @param {params} params - params object
276276
* @returns {boolean} true if user was updated
277277
**/
278-
usersApi.updateUser = function(params) {
278+
usersApi.updateUser = async function(params) {
279279
var argProps = {
280280
'user_id': {
281281
'required': true,
@@ -346,7 +346,7 @@ usersApi.updateUser = function(params) {
346346

347347
if (updatedMember.password) {
348348
passwordNoHash = updatedMember.password;
349-
updatedMember.password = common.sha512Hash(updatedMember.password);
349+
updatedMember.password = await common.argon2Hash(updatedMember.password);
350350
if (params.member._id !== params.qstring.args.user_id) {
351351
updatedMember.password_changed = 0;
352352
}

api/utils/common.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ var common = {},
1111
logger = require('./log.js'),
1212
mcc_mnc_list = require('mcc-mnc-list'),
1313
plugins = require('../../plugins/pluginManager.js'),
14-
countlyConfig = require('./../config', 'dont-enclose');
14+
countlyConfig = require('./../config', 'dont-enclose'),
15+
argon2 = require('argon2');
1516

1617
var matchHtmlRegExp = /"|'|&(?!amp;|quot;|#39;|lt;|gt;|#46;|#36;)|<|>/;
1718
var matchLessHtmlRegExp = /[<>]/;
@@ -458,6 +459,15 @@ common.sha512Hash = function(str, addSalt) {
458459
return crypto.createHmac('sha512', salt + '').update(str + '').digest('hex');
459460
};
460461

462+
/**
463+
* Create argon2 hash string
464+
* @param {string} str - string to hash
465+
* @returns {promise} hash promise
466+
**/
467+
common.argon2Hash = function(str) {
468+
return argon2.hash(str);
469+
};
470+
461471
/**
462472
* Create MD5 hash from provided value
463473
* @param {string} str - value to hash

0 commit comments

Comments
 (0)