You are here

function _digest_md5_challenge in Secure Site 8

Same name and namespace in other branches
  1. 6.2 digest_md5/digest_md5.php \_digest_md5_challenge()
  2. 7.2 digest_md5/digest_md5.php \_digest_md5_challenge()

Prepare a challenge.

Parameters

$edit:

  • values
  • fields
  • new

Return value

Digest challenge string.

1 call to _digest_md5_challenge()
_digest_md5_response in digest_md5/digest_md5.php
Process an authentication string.

File

digest_md5/digest_md5.php, line 143
This script implements the DIGEST-MD5 mechanism for all protocols. Only the root user should have access to this script and the database used to store passwords and nonce values.

Code

function _digest_md5_challenge($edit) {
  if (isset($edit['values'])) {
    $types = array(
      'qop' => "'%s'",
      'nc' => '%d',
      'opaque' => "'%s'",
      'hash' => "'%s'",
      'time' => '%d',
      'nonce' => "'%s'",
      'realm' => "'%s'",
    );
    foreach ($types as $field => $type) {
      if (!isset($edit['values'][$field])) {
        unset($types[$field]);
      }
      else {

        // Ensure that values appear in the same order as types.
        $values[$field] = $edit['values'][$field];
      }
    }
    if ($edit['new']) {

      //todo check here
      db_insert('securesite_nonce')
        ->fields($values)
        ->execute();

      //db_query("INSERT INTO `securesite_nonce` (". implode(', ', array_keys($values)) .") VALUES (". implode(', ', $types) .")", $values);
    }
    else {
      unset($types['nonce'], $types['realm']);
      $fields = array();
      foreach ($types as $field => $type) {
        $fields[] = "{$field} = {$type}";
      }
      db_update('securesite_nonce')
        ->fields($values)
        ->condition('nonce', $values['nonce'])
        ->condition('realm', $values['realm'])
        ->execute();

      //db_query("UPDATE `securesite_nonce` SET ". implode(', ', $fields) ." WHERE nonce = '%s' AND realm = '%s'", $values);
    }
  }
  if (isset($edit['challenge'])) {
    return implode(', ', $edit['challenge']);
  }
}