<commit_before>/*
This script updates the passwords of all users by hashing it (with the provided salt) - only execute this once, outherwise passwords are broken!
 */

'use strict';

const co = require('./common'),
  userDB = require('./database/user'),
  JSSHA = require('js-sha512'),
  async = require('async');

let salt = '';

console.log('\x1b[31m','This script updates the passwords of all users by hashing it (with the provided salt) - only execute this once, outherwise passwords are broken!','\x1b[0m');//strange stuff for red color

if(process.argv.length < 3 || process.argv.length > 3){
  console.log('To few (or many) arguments, please provide only a salt as an argument!');
  process.exit(1);
} else
  salt = process.argv[2];

userDB.find({})
.then((cursor) => {
  cursor.count().then((count) => console.log(count + ' users found, starting migration ...'));
  // I haven't found any other way to implement it than this one, maybe except for lazy evaluation via yield
  let q = async.queue((user, callback) => {
    let hashedPassword = JSSHA.sha512(user.password + salt);
    userDB.partlyUpdate({'_id': user._id}, {'$set': {'password': hashedPassword}}).then(() => {
      process.stdout.write('\rUpdated user ' + user._id + ' (out of order)');
      callback();
    });
  }, Infinity);

  cursor.forEach((user) => {
    if(!co.isEmpty(user) && user.passord && user._id){
      q.push(user);
    }
  });
  q.drain = function() {
    if (cursor.isClosed()) {
      console.log('\n');
      console.log('All Users have been updated');
      process.exit(0);
    }
  };
});<commit_msg>Fix typo in migration where no user was added to the processing queue<commit_after>/*
This script updates the passwords of all users by hashing it (with the provided salt) - only execute this once, outherwise passwords are broken!
 */

'use strict';

const co = require('./common'),
  userDB = require('./database/user'),
  JSSHA = require('js-sha512'),
  async = require('async');

let salt = '';

console.log('\x1b[31m','This script updates the passwords of all users by hashing it (with the provided salt) - only execute this once, outherwise passwords are broken!','\x1b[0m');//strange stuff for red color

if(process.argv.length < 3 || process.argv.length > 3){
  console.log('To few (or many) arguments, please provide only a salt as an argument!');
  process.exit(1);
} else
  salt = process.argv[2];

userDB.find({})
.then((cursor) => {
  cursor.count().then((count) => console.log(count + ' users found, starting migration ...'));
  // I haven't found any other way to implement it than this one, maybe except for lazy evaluation via yield
  let q = async.queue((user, callback) => {
    let hashedPassword = JSSHA.sha512(user.password + salt);
    userDB.partlyUpdate({'_id': user._id}, {'$set': {'password': <PASSWORD>}}).then(() => {
      process.stdout.write('\rUpdated user ' + user._id + ' (out of order)');
      callback();
    });
  }, Infinity);

  cursor.forEach((user) => {
    if(!co.isEmpty(user) && user.password && user._id){
      q.push(user);
    }
  });
  q.drain = function() {
    if (cursor.isClosed()) {
      console.log('\n');
      console.log('All Users have been updated');
      process.exit(0);
    }
  };
});
{'fraction_non_alphanumeric': 0.16753926701570682, 'fraction_numerical': 0.00985525100092393, 'mean_word_length': 3.594059405940594, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7539042', 'n_tokens_mistral': 1022, 'n_tokens_neox': 999, 'n_words': 310}