secure_hash
[ class tree: secure_hash ] [ index: secure_hash ] [ all elements ]

Source for file secure_hash.example.php

Documentation is available at secure_hash.example.php

  1. <?php
  2. /**
  3.  * Secure password hashing class example
  4.  * @package secure_hash
  5.  * @author Julius Beckmann
  6.  * @link http://juliusbeckmann.de/classes/secure_hash/
  7.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8.  * @filesource
  9.  */
  10. /**
  11.  * Example how to use secure_hash
  12.  * @name Secure password hashing class example
  13.  * @access public
  14.  * @package secure_hash
  15.  */
  16.  
  17. /**
  18.  * Password we want to hash.
  19.  */
  20. $password 'GoodPassword';
  21. echo "Our password: '$password' <br/>\n";
  22.  
  23. /**
  24.  * Create secure_hash object.
  25.  */
  26. require_once('secure_hash.class.php');
  27. $secure_hash new secure_hash;
  28.  
  29. /**
  30.  * Create a new permutation rule if needed
  31.  * Read documentation about this method!
  32.  */
  33. //echo 'New permutation: '.$secure_hash->_new_permutation()."<br/>\n";
  34.  
  35. /**
  36.  * Setting a global salt which is NOT saved in formated hash.
  37.  * Read documentation about this value!
  38.  */
  39. $secure_hash->salt_global '';
  40.  
  41. /**
  42.  * Changing hashing method.
  43.  */
  44. $secure_hash->hashing_method 'sha1';
  45.  
  46. /**
  47.  * Generate formated hash.
  48.  */
  49. $hash $secure_hash->hash($password);
  50. echo "Formated hash: '$hash' <br/>\n";
  51.  
  52. /** 
  53.  * Test generated hash against password.
  54.  */
  55. if($secure_hash->check($hash$password)) {
  56.     echo "Password '$password' fits to the hash.<br/>\n";
  57. }else{
  58.     echo "Password '$password' DOES NOT fit to the hash.<br/>\n";
  59. }
  60.  
  61. /** 
  62.  * Test a incorrect password against hash.
  63.  */
  64. $password 'incorrect password';
  65. if($secure_hash->check($hash$password)) {
  66.     echo "Password '$password' fits to the hash.<br/>\n";
  67. }else{
  68.     echo "Password '$password' DOES NOT fit to the hash.<br/>\n";
  69. }
  70.  
  71.  
  72.  
  73. ?>

Documentation generated on Fri, 29 Jan 2010 08:49:12 +0100 by phpDocumentor 1.4.3