Source for file Nonce.php
Documentation is available at Nonce.php
* @author Bill Shupp <hostmaster@shupp.org>
* @copyright 2009 Bill Shupp
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
* @link http://pearopenid.googlecode.com
require_once 'OpenID/Store.php';
require_once 'OpenID.php';
* Handles nonce functionality. Requires the OP Endpoint URL nonces are to be
* @author Bill Shupp <hostmaster@shupp.org>
* @copyright 2009 Bill Shupp
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
* @link http://pearopenid.googlecode.com
* Constant for the parameter used with OpenID 1.1 nonces in the return_to URL
const RETURN_TO_NONCE =
'openid.1_1_nonce';
* The OP Endoint URL a nonce is associated with
* Default clock skew, i.e. how long in the past we're willing to allow for.
* Sets the OP endpoint URL, and optionally the clock skew and custom storage
* @param string $opEndpointURL OP Endpoint URL
* @param int $clockSkew How many seconds old can a
* Checks to see if the response nonce has been seen before. If not, store it
* and then validate its syntax
* @param string $nonce The nonce from the OP response
* @return bool true on success, false on failure
// See if it is already stored
* Validates the syntax of a nonce, as well as checks to see if its timestamp is
* within the allowed clock skew
* @param mixed $nonce The nonce to validate
* @return bool true on success, false on failure
$result =
preg_match('/(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z(.*)/',
if ($result !=
1 ||
count($matches) !=
8) {
* Creates a nonce, but does not store it. You may specify the lenth of the
* random string, as well as the time stamp to use.
* @param int $length Lenth of the random string, defaults to 6
* @param int $time A unix timestamp in seconds
* @return string The nonce
* @see createNonceAndStore()
$time =
($time ===
null) ?
time() :
$time;
$chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$chars .=
'abcdefghijklmnopqrstuvwxyz';
for ($i =
0; $i <
$length; $i++
) {
* Creates a nonce and also stores it.
* @param int $length Lenth of the random string, defaults to 6
* @param int $time A unix timestamp in seconds
* @return string The nonce
Documentation generated on Tue, 15 Dec 2009 19:00:56 -0800 by phpDocumentor 1.4.3