<commit_before>var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var bcrypt = require('bcrypt-nodejs');

var config = require('../config');

var UserSchema = new Schema({
  username:  {type: String, required: true, index: {unique: true}},
  email:  {type: String, required: true, unique: true},
  password: {type: String, required: true},
  role: {type: String, required: true, default: 'user'}
})

UserSchema.pre('save', function(next) {
  var user = this;

  // only hash the password if it has been modified (or is new)
  if (!user.isModified('password')) return next();

  // generate a salt
  bcrypt.genSalt(config.SALT_WORK_FACTOR, function(err, salt) {
      if (err) return next(err);

      // hash the password using our new salt
      bcrypt.hash(user.password, salt, function(err, hash) {
          if (err) return next(err);

          // override the cleartext password with the hashed one
          user.password = hash;
          next();
      });<commit_msg>Fix changed interface in bCrypt<commit_after>var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var bcrypt = require('bcrypt-nodejs');

var config = require('../config');

var UserSchema = new Schema({
  username:  {type: String, required: true, index: {unique: true}},
  email:  {type: String, required: true, unique: true},
  password: {type: String, required: true},
  role: {type: String, required: true, default: 'user'}
})

UserSchema.pre('save', function(next) {
  var user = this;

  // only hash the password if it has been modified (or is new)
  if (!user.isModified('password')) return next();

  // generate a salt
  bcrypt.genSalt(config.SALT_WORK_FACTOR, function(err, salt) {
      if (err) return next(err);

      // hash the password using our new salt
      bcrypt.hash(user.password, salt, undefined, function(err, hash) {
          if (err) return next(err);

          // override the cleartext password with the hashed one
          user.password = <PASSWORD>;
          next();
      });
{'fraction_non_alphanumeric': 0.1383242439266237, 'fraction_numerical': 0.0, 'mean_word_length': 3.406113537117904, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '621155', 'n_tokens_mistral': 609, 'n_tokens_neox': 603, 'n_words': 205}