<commit_before>module.exports = (function(){
    'use strict';

    var mongoose = require('mongoose'),
        q = require('q'),
        error = require('../../utils/error'),
        async = require('async'),
        crud = require('./mixins/crud'),
        _ = require('underscore'),
        collectionName = 'users',
        filterFactory = require('./search/filterFactory'),
        schema = require('./schemas/user');

    function handleUser(err, doc, deferred){
        if(err) {
            deferred.reject(error(err));
        }
        else if (doc !== null) {
            deferred.resolve(doc);
        }
        else {
            deferred.reject(error(404));
        }
    }

    var user = Object.create(crud, {
        model: {value: mongoose.model(collectionName, schema)},
        privateFields: {value: ['salt', 'pass_hash','identities.basic.pass_hash']}
    });

    user.getByEmail = function(email) {
        var deferred = q.defer();

        this.model.findOne({email: email}, this.buildIncludes()).lean().exec(function(err, doc){
            handleUser(err, doc, deferred);
        });

        return deferred.promise;
    };

    user.basicAuthentication = function(login, password){
        var deferred = q.defer();

        this.model.findOne({'identities.basic.login': login}, function(err, doc){
            var valid = (doc !== null) ? doc.authenticate(password) : false;

            if(!valid){
                handleUser(null, null, deferred);
            }
            else {
                handleUser(err, doc, deferred);
            }
        });
<commit_msg>Renamed authentication method to "basicAuthentication" and added new fields to ignore list for security.<commit_after>module.exports = (function(){
    'use strict';

    var mongoose = require('mongoose'),
        q = require('q'),
        error = require('../../utils/error'),
        async = require('async'),
        crud = require('./mixins/crud'),
        _ = require('underscore'),
        collectionName = 'users',
        filterFactory = require('./search/filterFactory'),
        schema = require('./schemas/user');

    function handleUser(err, doc, deferred){
        if(err) {
            deferred.reject(error(err));
        }
        else if (doc !== null) {
            deferred.resolve(doc);
        }
        else {
            deferred.reject(error(404));
        }
    }

    var user = Object.create(crud, {
        model: {value: mongoose.model(collectionName, schema)},
        privateFields: {value: ['salt', 'pass_hash','identities.basic.hash','identities.basic.salt']}
    });

    user.getByEmail = function(email) {
        var deferred = q.defer();

        this.model.findOne({email: email}, this.buildIncludes()).lean().exec(function(err, doc){
            handleUser(err, doc, deferred);
        });

        return deferred.promise;
    };

    user.basicAuthentication = function(login, password){
        var deferred = q.defer();

        this.model.findOne({'identities.basic.login': login}, function(err, doc){
            var valid = (doc !== null) ? doc.basicAuthentication(password) : false;

            if(!valid){
                handleUser(null, null, deferred);
            }
            else {
                handleUser(err, doc, deferred);
            }
        });

{'fraction_non_alphanumeric': 0.15212798068216118, 'fraction_numerical': 0.0018110473890733474, 'mean_word_length': 2.082790697674419, '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': '5967327', 'n_tokens_mistral': 938, 'n_tokens_neox': 894, 'n_words': 181}