function storePasswordHashIntoDatabase(rxDatabase) {
  if (!rxDatabase.password) {
    return Promise.resolve(false);
  }

  var pwHash = hash(rxDatabase.password);
  return rxDatabase.internalStore.get(LOCAL_PREFIX + 'pwHash')["catch"](function () {
    return null;
  }).then(function (pwHashDoc) {
    /**
     * if pwHash was not saved, we save it,
     * this operation might throw because another instance runs save at the same time,
     */
    if (!pwHashDoc) {
      return rxDatabase.internalStore.put({
        _id: LOCAL_PREFIX + 'pwHash',
        value: pwHash
      })["catch"](function () {
        return null;
      }).then(function () {
        return true;
      });
    } else if (pwHash !== pwHashDoc.value) {
      // different hash was already set by other instance
      return rxDatabase.destroy().then(function () {
        throw newRxError('DB1', {
          passwordHash: hash(rxDatabase.password),
          existingPasswordHash: pwHashDoc.value
        });
      });
    }

    return true;
  });
}
/**
 * validates and inserts the password hash into the internal collection
 * to ensure there is/was no other instance with a different password
 * which would cause strange side effects when both instances save into the same db
 */
validates and inserts the password hash into the internal collection
to ensure there is/was no other instance with a different password
which would cause strange side effects when both instances save into the same db
validates and inserts the password hash into the internal collection to ensure there is / was no other instance with a different password which would cause strange side effects when both instances save into the same db
function storePasswordHashIntoDatabase(rxDatabase) {
  if (!rxDatabase.password) {
    return Promise.resolve(false);
  }
  var pwHash = hash(rxDatabase.password);
  return rxDatabase.internalStore.get(LOCAL_PREFIX + 'pwHash')["catch"](function () {
    return null;
  }).then(function (pwHashDoc) {
    if (!pwHashDoc) {
      return rxDatabase.internalStore.put({
        _id: LOCAL_PREFIX + 'pwHash',
        value: pwHash
      })["catch"](function () {
        return null;
      }).then(function () {
        return true;
      });
    } else if (pwHash !== pwHashDoc.value) {
      return rxDatabase.destroy().then(function () {
        throw newRxError('DB1', {
          passwordHash: hash(rxDatabase.password),
          existingPasswordHash: pwHashDoc.value
        });
      });
    }
    return true;
  });
}
function storePasswordHashIntoDatabase ( rxDatabase ) { if ( ! rxDatabase . password ) { return Promise . resolve ( false ) ; } var pwHash = hash ( rxDatabase . password ) ; return rxDatabase . internalStore . get ( LOCAL_PREFIX + 'pwHash' ) [ "catch" ] ( function ( ) { return null ; } ) . then ( function ( pwHashDoc ) { if ( ! pwHashDoc ) { return rxDatabase . internalStore . put ( { _id : LOCAL_PREFIX + 'pwHash' , value : pwHash } ) [ "catch" ] ( function ( ) { return null ; } ) . then ( function ( ) { return true ; } ) ; } else if ( pwHash !== pwHashDoc . value ) { return rxDatabase . destroy ( ) . then ( function ( ) { throw newRxError ( 'DB1' , { passwordHash : hash ( rxDatabase . password ) , existingPasswordHash : pwHashDoc . value } ) ; } ) ; } return true ; } ) ; }
validates and inserts the password hash into the internal collection
 to ensure there is/was no other instance with a different password
 which would cause strange side effects when both instances save into the same db
validates and inserts the password hash into the internal collection to ensure there is / was no other instance with a different password which would cause strange side effects when both instances save into the same db
/**
     * if pwHash was not saved, we save it,
     * this operation might throw because another instance runs save at the same time,
     */ // different hash was already set by other instance