<commit_before>const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const User = new Schema({
  username: String,
  password: String,
  admin: { type: Boolean, default: false}
});

// create new User document
User.statics.create = function(username, password){
  const user =  new this({
    username,
    password
  });
  // return the promise
  return user.save();
};

User.statics.findOneByUsername = function(username){
  return this.findOne({
    username
  }).exec();
};

// verify the password of the User document
User.methods.verify = function(password){
  return this.password === password;
};

User.methods.assignAdmin = function(){
  this.admin = true;
  return this.save();
};

module.exports = mongoose.model('User', User);<commit_msg>user password using hash<commit_after>const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const crypto = require('crypto');
const config = require('../config');

const User = new Schema({
  username: String,
  password: String,
  admin: { type: Boolean, default: false}
});

// create new User document
User.statics.create = function(username, password){
  // password encode using by HMAC-SHA1(Hash)
  const encrypted = crypto.createHmac('sha1', config.secret)
                    .update(password)
                    .digest('base64');

  const user =  new this({
    username,
    password: encrypted
  });
  // return the promise
  return user.save();
};

User.statics.findOneByUsername = function(username){
  return this.findOne({
    username
  }).exec();
};

// verify the password of the User document
User.methods.verify = function(password){
  // password decode
  const encrypted = crypto.createHmac('sha1', config.secret)
                    .update(password)
                    .digest('base64');

  return this.password === encrypted;
};

User.methods.assignAdmin = function(){
  this.admin = true;
  return this.save();
};

module.exports = mongoose.model('User', User);
{'fraction_non_alphanumeric': 0.1383679675620882, 'fraction_numerical': 0.0035478966041561076, 'mean_word_length': 3.4660633484162897, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4897922', 'n_tokens_mistral': 573, 'n_tokens_neox': 566, 'n_words': 156}