<commit_before>var db = require('./database.js');

module.exports = (function(client, username, password, fn) {
  if (!username || !password) {
    return fn(null, false);
  }
  
  db.get(function(err, db) {
    if (err) {
      return fn(err, false);
    }
    
    db.collection('keys').findOne({key: username, token: password}, function(err, key) {
      if (err) {
	return fn(err, false);
      }

      if (key) {
	client.key = key.key;
	return fn(null, true);
      }
      fn(null, false);
    });
  });
});<commit_msg>Using the new device.key field in the authentication<commit_after>var db = require('./database.js');

module.exports = (function(client, username, password, fn) {
  if (!username || !password) {
    return fn(null, false);
  }
  
  db.get(function(err, db) {
    if (err) {
      return fn(err, false);
    }
    
    db.collection('devices').findOne(
      {'key.key': username, 'key.token': password}, function(err, device) {
	if (err) {
	  return fn(err, false);
	}
	
	if (device) {
	  client.key = device.key.key;
	  return fn(null, true);
	}
	fn(null, false);
      });
  });
});
{'fraction_non_alphanumeric': 0.18198198198198198, 'fraction_numerical': 0.0, 'mean_word_length': 2.8178694158075603, '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': '1957819', 'n_tokens_mistral': 392, 'n_tokens_neox': 385, 'n_words': 90}