<?php
/* $Id$
 *
 * Created by Audun Larsen larsen@xqus.com)
 *
 * Copyright 2007 Audun Larsen
 * Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported
 * http://creativecommons.org/licenses/by-nc-sa/3.0/
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */ 
$str  ='';
$hash '';
if(isset(
$_POST['str']) && isset($_POST['algorithm'])) {
  foreach(
$_POST['algorithm'] as $algorithm => $checked) {
    
$hash .= $algorithm.': '.hash($algorithm$_POST['str'])."<br />";
  }
  
  
$str=htmlentities($_POST['str']);
}

?>
<html>
<head>
<title>PHP hasher</title>
</head>

<body>

<?php
if(extension_loaded('hash')) {  
  
$algorithms hash_algos();
  if(isset(
$hash)) {
    echo 
$hash."<br /><br />";
  }
  echo 
'<form method="post">';
  echo 
'Hash string: <input type="text" name="str" value="'.$str.'" /><br />';
  echo 
'Hash algorithm: ';  
  foreach(
$algorithms as$algorithm) {
    if(isset(
$_POST['algorithm'][$algorithm])) {
      echo 
'<input type="checkbox" name="algorithm['.$algorithm.']" checked>'.$algorithm.' ';
    } else {
      echo 
'<input type="checkbox" name="algorithm['.$algorithm.']" >'.$algorithm.' ';
    }
  }  
  echo 
'<br /><input type="submit" value="Hash">';
  echo 
'</form>';
  
} else {
  echo 
"<p>This script requires the hash extension.</p>";
}
?>
<p><a href="hash.phps">Display script source</a></p>
</body>
</html>