<commit_before>/////////////////////////////////////////
// Do the CORS request to the back-end //
// Or refresh the token                //
/////////////////////////////////////////

'use strict';

var crypto  = require('crypto');
var request = require('request');
var bcrypt  = require('bcryptjs');

module.exports = function (db, config) {
    var logger = require('../../lib/log')(config);

    return function (req, res, next) {
        if (!req.form.isValid) {
            Error.emit(res, 400, '400 - Bad Request', req.form.errors);
            return;
        }

        var username = req.form.username;
        var password = <PASSWORD>.form.password;
        var sha256 = crypto.createHash('sha256');
        sha256.update(username + ':' + password);
        var hash = sha256.digest('base64');

        logger.info('Asking axel back end with : ' + username + '/' + password);
        bcrypt.compare(req.form.password, hash, function (err, hash) {
            /*
            setTimeout(function () {
                Error.emit(res, 400, '400 - Invalid username/password');
            }, 1400);
            */
            req.user = {
                username: username,
                hash: hash
            };
            next();
        });
    };
};<commit_msg>Sha512 & demo user<commit_after>/////////////////////////////////////////
// Do the CORS request to the back-end //
// Or refresh the token                //
/////////////////////////////////////////

'use strict';

var crypto  = require('crypto');
var request = require('request');
var bcrypt  = require('bcryptjs');

module.exports = function (db, config) {
    var logger = require('../../lib/log')(config);

    return function (req, res, next) {
        if (!req.form.isValid) {
            Error.emit(res, 400, '400 - Bad Request', req.form.errors);
            return;
        }

        var username = req.form.username;
        var password = <PASSWORD>.form.password;
        var hash = bcrypt.hashSync(password);
        var sha512 = crypto.createHash('sha512');
        sha512.update(username + ':' + password);
        var token = sha512.digest('hex');

        logger.info('Asking axel back end with : ' + username + '/' + password);
        if (bcrypt.compareSync(req.form.password, hash)) {
            req.user = {
                id: 1,
                username: username,
                isAdmin: false,
                fundations: [
                    {
                        id: 1,
                        name: 'BDE',
                        isInBoard: true
                    },
                    {
                        id: 2,
                        name: 'UNG',
                        isInBoard: false
                    }
                ],
                tickets: [
                    {
                        id: 1,
                        username: 35342,
                        student: true,
                        contributor: true,
                        paid: true,
                        paid_at: new Date(),
                        paid_with: 'buckutt',
                        event_id: 1,
                        price_id: 1,
                        mean_of_payment_id: 1
                    }
                ],
                token: token
            };
            next();
        } else {
            Error.emit(res, 400, '400 - Invalid username/password');
            return;
        }
    };
};
{'fraction_non_alphanumeric': 0.16423995340710543, 'fraction_numerical': 0.02009318578916715, 'mean_word_length': 1.0680313064419025, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7559278', 'n_tokens_mistral': 925, 'n_tokens_neox': 829, 'n_words': 208}