var models  = require('../models');
var crypto = require('crypto');

var User = function() {
    
    var authenticateUser = function(uuser, upass, callback){
        var upass = crypto.createHash('md5').update(upass).digest("hex");

        models.User.findAll({where:{nombre: uuser, pass: upass}}).then(function(user){
              
            if(user.length > 0){
                // user found
                return callback(1);    
            }
            return callback(0);
            
        }).catch(function(err){
           console.log(err);
           return callback(0);
        });
    }
    
    return {
        authenticateUser: authenticateUser
    }

}();

module.exports = User;
