<?xml version="1.0" encoding="utf-8"?> <!-- $Revision$ --> <refentry xml:id="oauthprovider.generatetoken" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <refnamediv> <refname>OAuthProvider::generateToken</refname> <refpurpose>Generate a random token</refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <methodsynopsis> <modifier>final</modifier> <modifier>public</modifier> <modifier>static</modifier> <type>string</type><methodname>OAuthProvider::generateToken</methodname> <methodparam><type>int</type><parameter>size</parameter></methodparam> <methodparam choice="opt"><type>bool</type><parameter>strong</parameter><initializer>&false;</initializer></methodparam> </methodsynopsis> <para> Generates a <type>string</type> of pseudo-random bytes. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <variablelist> <varlistentry> <term><parameter>size</parameter></term> <listitem> <para> The desired token length, in terms of bytes. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>strong</parameter></term> <listitem> <para> Setting to &true; means <literal>/dev/random</literal> will be used for entropy, as otherwise the non-blocking <literal>/dev/urandom</literal> is used. This parameter is ignored on Windows. </para> </listitem> </varlistentry> </variablelist> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> The generated token, as a <type>string</type> of bytes. </para> </refsect1> <refsect1 role="errors"> &reftitle.errors; <para> If the <parameter>strong</parameter> parameter is &true;, then an <constant>E_WARNING</constant> level error will be emitted when the fallback <function>rand</function> implementation is used to fill the remaining random bytes (e.g., when not enough random data was found, initially). </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <example> <title><function>OAuthProvider::generateToken</function> example</title> <programlisting role="php"> <![CDATA[ <?php $p = new OAuthProvider(); $t = $p->generateToken(4); echo strlen($t), PHP_EOL; echo bin2hex($t), PHP_EOL; ?> ]]> </programlisting> &example.outputs.similar; <screen> <![CDATA[ 4 b6a82c27 ]]> </screen> </example> </refsect1> <refsect1 role="notes"> &reftitle.notes; <note> <para> When not enough random data is available to the system, this function will fill the remaining random bytes using the internal PHP <function>rand</function> implementation. </para> </note> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <simplelist> <member><function>openssl_random_pseudo_bytes</function></member> <member><function>mcrypt_create_iv</function></member> </simplelist> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"~/.phpdoc/manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->