Location: PHPKode > scripts > Password > password/Example/Password.Example.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <title>PHP5 Class - Password</title>
    <link href="Password.Example.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1 id="example-001">Example 001. Single password</h1>
<pre class="input_code">
&lt;?php
require_once 'Password.php';
$pwd = Password::getInstance()-&gt;generate();
<span>// This is equal to:
// $pwd = Password::getInstance();
// $pwd-&gt;generate();</span>
print $pwd;
?&gt;
</pre>
<h2>Output:</h2>
<pre class="output_code">
2Vccmq3n
</pre>

<hr />

<h1 id="example-002">Example 002. Single password with dictionary file</h1>
<pre class="input_code">
&lt;?php
require_once 'Password.php';
$pwd = Password::getInstance()-&gt;setDictionary('passwords')-&gt;generate();
<span>// This is equal to:
// $pwd = Password::getInstance();
// $pwd-&gt;setDictionary('passwords');
// $pwd-&gt;generate();
// or
// $pwd = Password::getInstance();
// $pwd-&gt;setDictionary('passwords')-&gt;generate();</span>
print $pwd;
?&gt;
</pre>
<h2>Output:</h2>
<pre class="output_code">
B77gEATH
</pre>

<hr />

<h1 id="example-003">Example 003. Single password with dictionary array</h1>
<pre class="input_code">
&lt;?php
require_once 'Password.php';
$pwd_array = array('Sample', 'Example', 'Variant', 'Version');
$pwd = Password::getInstance()
     -&gt;setDictionary($pwd_array)
     -&gt;generate();
print $pwd;
?&gt;
</pre>
<h2>Output:</h2>
<pre class="output_code">
SaMPl98H
</pre>

<hr />

<h1 id="example-004">Example 004. Single password with custom alphabet</h1>
<pre class="input_code">
&lt;?php
require_once 'Password.php';
$pwd = Password::getInstance()
     -&gt;setAlphabet(array('a', 'e'), array('b', 'c', 'd'))
     -&gt;generate();
print_r($pwd);
?&gt;
</pre>
<h2>Output:</h2>
<pre class="output_code">
aced2dA6
</pre>

<hr />

<h1 id="example-005">Example 005. Multiple passwords</h1>
<pre class="input_code">
&lt;?php
require_once 'Password.php';
$pwd = Password::getInstance()
       -&gt;generate(32, 3);
print_r($pwd);
?&gt;
</pre>
<h2>Output:</h2>
<pre class="output_code">
Array
(
    [0] =&gt; IFnXkOtMx3hC773QyGURytuBSI106J3c
    [1] =&gt; oyj35PiskMLk0H2w9d98PMOxpNE6ZPmE
    [2] =&gt; Xn16sNEl4SY4zkUto0JiJI0iqIa25pAv
)
</pre>

<hr />

<h1 id="example-006">Example 006. Multiple passwords with custom alphabet, dictionary, custom length and only in lowercase</h1>
<pre class="input_code">
&lt;?php
require_once 'Password.php';
$pwd = Password::getInstance()
       -&gt;setAlphabet(array('a'), array('b'))
       -&gt;setDictionary('passwords')
       -&gt;generate(32, 3, Password::LOWER);
print_r($pwd);
?&gt;
</pre>
<h2>Output:</h2>
<pre class="output_code">
Array
(
    [0] =&gt; c1ralbaba2a0a0ab
    [1] =&gt; 6heat1abab8baba9
    [2] =&gt; b0igeba831ababab
)
</pre>

<hr />

<h1 id="example-007">Example 007. Silly random bitfields (contain only digits 0 and 1)</h1>
<pre class="input_code">
&lt;?php
require_once 'Password.php';
$pwd = Password::getInstance()
       -&gt;setAlphabet(array(0, 1))
       -&gt;setDictionary()
       -&gt;generate(array(32, 0), 3));
print_r($pwd);
?&gt;
</pre>
<h2>Output:</h2>
<pre class="output_code">
Array
(
    [0] =&gt; 01100111101110101110110000111101
    [1] =&gt; 11011001000111011101110001111000
    [2] =&gt; 10000101011111011111101111101011
)
</pre>
</body>
</html>
Return current item: Password