<commit_before>/** USER MODEL **/

const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');

const userSchema = mongoose.Schema({
  username: {
    type: String,
    index: true,
    lowercase: true
  },
  password: {
    type: String
  },
  email: {
    type: String
  },
  name: {
    type: String
  },
  itemIdArray: [mongoose.Schema.Types.ObjectId],
  tipIdArray: [mongoose.Schema.Types.ObjectId],
  admin: {
    type: Boolean,
  default: [false]
  }
});


/* MODULE EXPORTS */

const User = module.exports = mongoose.model('User', userSchema);

/* export functions */
module.exports.createUser = function(newUser, callback){
	bcrypt.genSalt(10, function(err, salt) {
	    bcrypt.hash(newUser.password, salt, function(err, hash) {
	        newUser.password = hash;
	        newUser.save(callback);
	    });
	});
}

module.exports.getUserByUsername = function(username, callback){
	let query = {username: username.toLowerCase()};
	User.findOne(query, callback);
}

module.exports.getUserById = function(id, callback){
	User.findById(id, callback);
}

module.exports.comparePassword = function(candidatePassword, hash, callback){
	bcrypt.compare(candidatePassword, hash, function(err, isMatch) {
    	if(err) throw err;
    	callback(null, isMatch);
	});
}
<commit_msg>make sure that username password and emails are lowercase in system and when comparing<commit_after>/** USER MODEL **/

const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');

const userSchema = mongoose.Schema({
  username: {
    type: String,
    index: true,
    lowercase: true
  },
  password: {
    type: String
  },
  email: {
    type: String,
    lowercase: true
  },
  name: {
    type: String
  },
  itemIdArray: [mongoose.Schema.Types.ObjectId],
  tipIdArray: [mongoose.Schema.Types.ObjectId],
  admin: {
    type: Boolean,
  default: [false]
  }
});


/* MODULE EXPORTS */

const User = module.exports = mongoose.model('User', userSchema);

/* export functions */
module.exports.createUser = function(newUser, callback){
	bcrypt.genSalt(10, function(err, salt) {
	    bcrypt.hash(newUser.password, salt, function(err, hash) {
	        newUser.password = <PASSWORD>;
	        newUser.save(callback);
	    });
	});
}

module.exports.getUserByUsername = function(username, callback){
	let query = {username: username.toLowerCase()};
	User.findOne(query, callback);
}

module.exports.getUserById = function(id, callback){
	User.findById(id, callback);
}

module.exports.comparePassword = function(candidatePassword, hash, callback){
	bcrypt.compare(candidatePassword.toLowerCase(), hash, function(err, isMatch) {
    	if(err) throw err;
    	callback(null, isMatch);
	});
}

{'fraction_non_alphanumeric': 0.14386617100371749, 'fraction_numerical': 0.001486988847583643, 'mean_word_length': 3.919561243144424, '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': '7410910', 'n_tokens_mistral': 880, 'n_tokens_neox': 885, 'n_words': 187}