File tree 4 files changed +179
-88
lines changed 4 files changed +179
-88
lines changed Original file line number Diff line number Diff line change @@ -234,9 +234,9 @@ usersApi.createUser = function(params) {
234
234
/**
235
235
* Creates user document with hashed password
236
236
**/
237
- function createUser ( ) {
237
+ async function createUser ( ) {
238
238
var passwordNoHash = newMember . password ;
239
- newMember . password = common . sha512Hash ( newMember . password ) ;
239
+ newMember . password = await common . argon2Hash ( newMember . password ) ;
240
240
newMember . password_changed = 0 ;
241
241
newMember . created_at = Math . floor ( ( ( new Date ( ) ) . getTime ( ) ) / 1000 ) ; //TODO: Check if UTC
242
242
newMember . admin_of = newMember . admin_of || [ ] ;
@@ -275,7 +275,7 @@ usersApi.createUser = function(params) {
275
275
* @param {params } params - params object
276
276
* @returns {boolean } true if user was updated
277
277
**/
278
- usersApi . updateUser = function ( params ) {
278
+ usersApi . updateUser = async function ( params ) {
279
279
var argProps = {
280
280
'user_id' : {
281
281
'required' : true ,
@@ -346,7 +346,7 @@ usersApi.updateUser = function(params) {
346
346
347
347
if ( updatedMember . password ) {
348
348
passwordNoHash = updatedMember . password ;
349
- updatedMember . password = common . sha512Hash ( updatedMember . password ) ;
349
+ updatedMember . password = await common . argon2Hash ( updatedMember . password ) ;
350
350
if ( params . member . _id !== params . qstring . args . user_id ) {
351
351
updatedMember . password_changed = 0 ;
352
352
}
Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ var common = {},
11
11
logger = require ( './log.js' ) ,
12
12
mcc_mnc_list = require ( 'mcc-mnc-list' ) ,
13
13
plugins = require ( '../../plugins/pluginManager.js' ) ,
14
- countlyConfig = require ( './../config' , 'dont-enclose' ) ;
14
+ countlyConfig = require ( './../config' , 'dont-enclose' ) ,
15
+ argon2 = require ( 'argon2' ) ;
15
16
16
17
var matchHtmlRegExp = / " | ' | & (? ! a m p ; | q u o t ; | # 3 9 ; | l t ; | g t ; | # 4 6 ; | # 3 6 ; ) | < | > / ;
17
18
var matchLessHtmlRegExp = / [ < > ] / ;
@@ -458,6 +459,15 @@ common.sha512Hash = function(str, addSalt) {
458
459
return crypto . createHmac ( 'sha512' , salt + '' ) . update ( str + '' ) . digest ( 'hex' ) ;
459
460
} ;
460
461
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
+
461
471
/**
462
472
* Create MD5 hash from provided value
463
473
* @param {string } str - value to hash
You can’t perform that action at this time.
0 commit comments