<?
function makeRandomPassword() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
function bytexor($a,$b,$l)
{
$c="";
for($i=0;$i<$l;$i++) {
$c.=$a{$i}^$b{$i};
}
return($c);
}
function binmd5($val)
{
return(pack("H*",md5($val)));
}
function decrypt_md5($msg,$heslo)
{
$key=$heslo;$sifra="";
$key1=binmd5($key);
while($msg) {
$m=substr($msg,0,16);
$msg=substr($msg,16);
$sifra.=$m=bytexor($m,$key1,16);
$key1=binmd5($key.$key1.$m);
}
echo "\n";
return($sifra);
}
function crypt_md5($msg,$heslo)
{
$key=$heslo;$sifra="";
$key1=binmd5($key);
while($msg) {
$m=substr($msg,0,16);
$msg=substr($msg,16);
$sifra.=bytexor($m,$key1,16);
$key1=binmd5($key.$key1.$m);
}
echo "\n";
return($sifra);
}
//key to encryption
$key = "type whatever you want your key to be";
//I would recommend cutting it off here and nameing the above
//functions.inc.php or something and includeing it in the below
//script
//make them a random password if you want
// $password = makeRandomPassword();
//if you dont then here is how to encrypt it
$password = crypt_md5($password, $key);
//and how to decrypt it
//$password = decrypt_md5($password, $key);
//check if password is valid here
$q = mysql_query("SELECT * FROM table WHERE password='$password'") or die(mysql_error());
$r = mysql_num_rows($q);
if($r != 1) {
echo "Wrong password.";
} else {
echo "Password Verified.";
}
?>
Hope that helps.