<commit_before>/*global ApiPassword, SRP, Meteor, beforeEach, after, afterEach */
/*jshint -W020 */

ApiPassword = {
  isPasswordValid: function (username, password) {
    "use strict";

    if (!username || !password) {
      throw new Meteor.Error('Username and password have to be provided');
    }

    var user = Meteor.users.findOne({username: username});
    if (!user) {
      throw new Error('User ' + username + ' not found');
    }

    if (!user.services || !user.services.password || !user.services.password.srp) {
      throw new Error('User has no password set');
    }

    var verifier = user.services.password.srp;
    var newVerifier = SRP.generateVerifier(password, {identity: verifier.identity, salt: verifier.salt});

    if (verifier.verifier === newVerifier.verifier) {
      return true;
    }

    return false;
  }
};<commit_msg>Replace SRP in Meteor 0.8.2+ #1<commit_after>/*global ApiPassword, SRP, Meteor, beforeEach, after, afterEach */
/*jshint -W020 */

ApiPassword = {
  isPasswordValid: function (username, password) {
    "use strict";

    if (!username || !password) {
      throw new Meteor.Error('Username and password have to be provided');
    }

    var user = Meteor.users.findOne({username: username});
    if (!user) {
      throw new Error('User ' + username + ' not found');
    }

    if (!user.services || !user.services.password) {
      throw new Error('User has no password set');
    }

    if (!user.services.password.srp) {

      // Meteor 0.8.2+
      var resultOfInvocation = Accounts._checkPassword(user, password);
      if (resultOfInvocation.error) {
        return false;
      } else {
        return true;
      }

    } else {

      // pre Meteor 0.8.2
      var verifier = user.services.password.srp;
      var newVerifier = SRP.generateVerifier(password, {identity: verifier.identity, salt: verifier.salt});
      if (verifier.verifier === newVerifier.verifier) {
        return true;
      }
    }
    return false;
  }
};
{'fraction_non_alphanumeric': 0.134470647265429, 'fraction_numerical': 0.008028098344204716, 'mean_word_length': 2.798095238095238, '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': '2305141', 'n_tokens_mistral': 639, 'n_tokens_neox': 609, 'n_words': 159}