Location: PHPKode > scripts > Salt Password Class > example.php
<!-------------------------------------------------->
<!--SaltPassword class, created by Ákos Nikházy	  -->
<!--This example show the usage of the class and  -->
<!--its functions.								  -->
<!-------------------------------------------------->

<html>
<head>
<title>Password Salt Class</title>
</head>
<body>
<?php

	require('SaltPassword.class.php');
	$pwObj = new SaltPassword(10,true);

?>
<h1>Why Salting?</h1>
<p>If you simply hash the passwords then there will be security risks. There are huge dictionaries that has a lot of md5 and other hashes with the plain text version. Other problem that if two user use the same password their hash will be the same too. If every password 
has its own, randomly generated seed, then it is nearly impossible to figure out what was the real password, and the same password will be not have the same hash. It is a good idea to regenerate salt time to time (for example at every login) to achive maximums security.</p>
<h1>Salting password:</h1>
<p>Lets say user has the password <strong>duck</strong> and in database he has the salt <strong>1f3870be274f6c49b3e31a0c6728957f</strong>. When he writes his password in a text field the saltPw() public function will salt the password:</br>
This is the result: <strong>
<?php 
	echo $pwObj->saltPw('duck','1f3870be274f6c49b3e31a0c6728957'); //saltPw returns the salted pw
?>
</strong><br/>
while the word <strong>duck</strong> with simple md5 hash: <strong><?php echo md5('duck'); ?></strong> </p>

<h1>Creating new password:</h1>
<p>When user registers the createPw() public function will return the password as plain text,the salt, and salted version of the password. The lenght of the password is optional between 6 and 20, the default value is 8. Special characters in password are optional, its default value is false. You can E-mail the plain text version and save the salted version and the salt in database.</br>
<pre>
<?php
	print_r($pwObj->createPw());//createPW returns an array
?>
</pre>
</p>
</body>
</html>

Return current item: Salt Password Class