PHP Classes

File: doc.php

Recommend this page to a friend!
  Classes of Jaume Presas  >  dasPass  >  doc.php  >  Download  
File: doc.php
Role: Documentation
Content type: text/plain
Description: Doc file
Class: dasPass
Generate a random password based on rules
Author: By
Last change:
Date: 11 years ago
Size: 3,630 bytes


Class file image Download
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />



<p>PHP class that returns a random password with lowercase characters, uppercase characters, numbers and/or special characters.</p>

<p>version: 1.0<br />
date: 2005-09-16<br />
author: Jaume Presas<br />
email: <a href=""></a><br />
license: freeware<br /><br />
You may use, modify and redistribute this software as you wish.</p>

<h2>How to use it</h2>

<p>Include the class file:<br /><br />
<span style="padding-left: 30px; font-family: monospace;">include('class.daspass.php');</span></p>

<p>Initialize the object:<br /><br />
<span style="padding-left: 30px; font-family: monospace;">$pass = new dasPass();</span></p>

<p>Call the method getPass() passing two variables: the first one is a string specifying the type of characters you want the password to have, and the second the number of characters:<br /><br />
<span style="padding-left: 30px; font-family: monospace;"$pass->$new_pass = $pass->getPass('aA1x',8)</span></p>

<p>Type of characters:
	<li>a for lowercase</li>
	<li>A for uppercase</li>
	<li>1 for numbers</li>
	<li>x for special characters</li>
Some examples:<br /><br />
To get 6 characters (lowercase, special): <span style="font-family: monospace;">$pass->$new_pass = $pass->getPass('ax',6);</span><br />
To get 10 characters (lowercase, uppercase, numbers): <span style="font-family: monospace;">$pass->$new_pass = $pass->getPass('aA1',10);</span><br />
To get 4 characters (uppercase, numbers, special): <span style="font-family: monospace;">$pass->$new_pass = $pass->getPass('A1x',4);</span><br />
To get 8 characters (lowercase, uppercase): <span style="font-family: monospace;">$pass->$new_pass = $pass->getPass('aA',6);</span>

<p>Print the given password:<br /><br />
<span style="padding-left: 30px; font-family: monospace;"$pass->print $new_pass;</span></p>


<div style="padding: 20px; border: 1px solid #c0c0c0; font-family: monospace;">
&lt;?<br /><br />
// include<br />
include('class.daspass.php');<br /><br />
// instantiate the object<br />
$pass = new dasPass();<br /><br />
// call the method<br />
$new_pass = $pass->getPass('aA1x',8);<br /><br />
// print the result<br />
print $new_pass;<br /><br />

if (isset($_POST['n'])) {
	$what = '';
	if (isset($_POST['a'])) {
		$what .= 'a';
	if (isset($_POST['A'])) {
		$what .= 'A';
	if (isset($_POST['1'])) {
		$what .= '1';
	if (isset($_POST['x'])) {
		$what .= 'x';
	$pass = new dasPass();
	$pass->n_min = 10;
	$new_pass = $pass->getPass($what,$_POST['n']);
	print "<p>This is your password: <span style=\"font-size: larger; font-weight: bold;\">$new_pass</span></p>\n";
	print "<p>Try again.</p>\n";

<p>The password has to contain:<br />
<form action="doc.php" method="post">
<input type="text" name="n" size="2" maxlength="2" value="8" /> characters<br />
<input type="checkbox" name="a" id="a" checked="checked"> lowercase characters<br />
<input type="checkbox" name="A" id="A" checked="checked" /> uppercase characters<br />
<input type="checkbox" name="1" id="1" checked="checked" /> numbers<br />
<input type="checkbox" name="x" id="x" checked="checked" /> special characters<br />
<input type="submit" value="Create password">