/**
  * Check if given code is correct
  *
  * @param string $code String to compare
  * @param Field $field String to compare
  * @param bool $clearSession
  * @return boolean
  */
 public function validCode($code, $field, $clearSession = true)
 {
     if ((int) $code === SessionUtility::getCaptchaSession($field->getUid()) && !empty($code)) {
         if ($clearSession) {
             SessionUtility::setCaptchaSession('', $field->getUid());
         }
         return true;
     }
     return false;
 }