Digest Authentication

Introduction

Digest authentication is a method of HTTP authentication that improves upon Basic authentication by providing a way to authenticate without having to transmit the password in clear text across the network.

This adapter allows authentication against text files containing lines having the basic elements of Digest authentication:

  • username, such as “joe.user
  • realm, such as “Administrative Area
  • MD5 hash of the username, realm, and password, separated by colons

The above elements are separated by colons, as in the following example (in which the password is “somePassword”):

1
someUser:Some Realm:fde17b91c3a510ecbaf7dbd37f59d4f8

Specifics

The digest authentication adapter, Zend\Authentication\Adapter\Digest, requires several input parameters:

  • filename - Filename against which authentication queries are performed
  • realm - Digest authentication realm
  • username - Digest authentication user
  • password - Password for the user of the realm

These parameters must be set prior to calling authenticate().

Identity

The digest authentication adapter returns a Zend\Authentication\Result object, which has been populated with the identity as an array having keys of realm and username. The respective array values associated with these keys correspond to the values set before authenticate() is called.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
use Zend\Authentication\Adapter\Digest as AuthAdapter;

$adapter = new AuthAdapter($filename,
                           $realm,
                           $username,
                           $password);

$result = $adapter->authenticate();

$identity = $result->getIdentity();

print_r($identity);

/*
Array
(
    [realm] => Some Realm
    [username] => someUser
)
*/

Table Of Contents

Previous topic

Database Table Authentication

Next topic

HTTP Authentication Adapter

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Digest Authentication on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.