Location: PHPKode > scripts > DasPass > class.daspass.php
<?
/************************************************************************
*																		*
*	dasPass																*
*																		*
*	This is a simple class that can be used to generate a random		*
*	password defined by rules that determine which types of characters	*
*	can be used.														*
*																		*
*	The generated password may include upper case letters, lower case	*
*	letters, numbers and special characters. Each character will only	*
*	appear in the password once.										*
*																		*
*	The length of the generated password is configured setting the		*
*	value of a class variable.											*
*																		*
*	version	: 1.0														*
*	date	: 2005-09-16												*
*	author	: Jaume Presas												*
*	email	: hide@address.com										*
*	license	: freeware													*
*																		*
*	You may use, modify and redistribute this software as you wish.		*
*																		*
************************************************************************/

/*

How to use it:

include('class.daspass.php');
$pass = new dasPass();
$new_pass = $pass->getPass('aA1x',8); //---> see examples below of how to call the method
print $new_pass;

//////////

Examples of how to call the method:

To get 6 characters (lowercase, special): $pass->getPass('ax',6);
To get 10 characters (lowercase, uppercase, numbers): $pass->getPass('aA1',10);
To get 4 characters (uppercase, numbers, special): $pass->getPass('A1x',4);
To get 8 characters (lowercase, uppercase): $pass->getPass('aA',6);

a for lowercase
A for uppercase
1 for numbers
x for special characters

*/

class dasPass {
	var $chars = '';
	var $chars_a = 'abcdefghijklmnopqrstuvwxyz';
	var $chars_A = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var $chars_1 = '1234567890';
	var $chars_x = '\!|#@$%&/()=?ยก*[]{}_+-<>"';
	function getPass($what,$n) {
		if ( (isset($what))&&(is_string($what))&&($what!='')&&(isset($n))&&(is_numeric($n)) ) {
			if (preg_match ("/a/", $what)) {
				$this->chars .= $this->chars_a;
			}
			if (preg_match ("/A/", $what)) {
				$this->chars .= $this->chars_A;
			}
			if (preg_match ("/1/", $what)) {
				$this->chars .= $this->chars_1;
			}
			if (preg_match ("/x/", $what)) {
				$this->chars .= $this->chars_x;
			}
			if ($this->chars!='') {
				$this->chars = str_shuffle($this->chars);
				return substr($this->chars, 0, $n);
			} else {
				print 'ERROR: Wrong parameters!';
			}
		} else {
			print 'ERROR: Wrong parameters!';
		}
	}
}

?>
Return current item: DasPass