<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

class DBWorkDblOptinToolPasswortAnfordern extends DBWorkDblOptin
{
  protected function getFeature()
  {
    return WebDblOptin::FEATURE_TOOL_PASSWORT_ANFORDERN;
  }

  protected function getOptinCode($pDblOptin)
  {
    $i = 0;
    do {
      $optin = md5($pDblOptin->getVarValue('name') . $pDblOptin->getVarValue('bearbdatum') . 'nl' . \SecurityOperations::generateSalt());
    } while ($this->istOptinVergeben($optin) && $i++ < static::MAX_OPTIN_CODE_GEN_RETRIES);

    if ($i == static::MAX_OPTIN_CODE_GEN_RETRIES) {
      throw new \RuntimeException('Irgendwas scheint mit dem Zufallsgenerator falsch zu laufen');
    }

    return $optin;
  }
}