lomerok
07.06.2008, 13:36
вот скрипт который записывает сгенериный Хэш в файл ...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=cp1251" />
</head>
<body>
<form method="GET">
Введите MD5 хэш :
<input type="text" name="hash">
<input type="submit" value="OK">
</form>
<?
global $hash2;
//$hash=isset($_GET['hash']) ? $_GET['hash'] : '';
//----------------Get Hash-------------------------------------------------------------------
function gethash($hash)
{
global $hash2;
$f="test.txt";
$file=file_get_contents($f);
preg_match("/(^|\n){$hash}:(\S+)/s",$file,$m);
if(isset($m[0]))
{$hash2=$m[0];print "ok";}
}
//---------------Random Hash---------------------------------------------------------------
function random($max)
{
$chars="12";
$size=StrLen($chars)-1;
$password=null;
while($max--)
{
$password.=$chars[rand(0,$size)];
}
$hash1="\n".md5($password).":$password";
gethash(md5($password));
print "<br>hash1=$hash1";
print "<br>hash2=$hash2";
if($hash1==$hash2) {print "<br>Существует !!!";}
else
{
print "<br>Записано !!!";
$file="test.txt";
$fo=fopen($file,"a+");
fwrite($fo,$hash1);
fclose($fo);
}
}
$i=0;
while($i<5)
{
random(2);
print "<br><hr>";
$i++;
}
?>
</body>
</html>
неработает $hash2 в функции random при вызове gethash(md5($password)). почему ??
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=cp1251" />
</head>
<body>
<form method="GET">
Введите MD5 хэш :
<input type="text" name="hash">
<input type="submit" value="OK">
</form>
<?
global $hash2;
//$hash=isset($_GET['hash']) ? $_GET['hash'] : '';
//----------------Get Hash-------------------------------------------------------------------
function gethash($hash)
{
global $hash2;
$f="test.txt";
$file=file_get_contents($f);
preg_match("/(^|\n){$hash}:(\S+)/s",$file,$m);
if(isset($m[0]))
{$hash2=$m[0];print "ok";}
}
//---------------Random Hash---------------------------------------------------------------
function random($max)
{
$chars="12";
$size=StrLen($chars)-1;
$password=null;
while($max--)
{
$password.=$chars[rand(0,$size)];
}
$hash1="\n".md5($password).":$password";
gethash(md5($password));
print "<br>hash1=$hash1";
print "<br>hash2=$hash2";
if($hash1==$hash2) {print "<br>Существует !!!";}
else
{
print "<br>Записано !!!";
$file="test.txt";
$fo=fopen($file,"a+");
fwrite($fo,$hash1);
fclose($fo);
}
}
$i=0;
while($i<5)
{
random(2);
print "<br><hr>";
$i++;
}
?>
</body>
</html>
неработает $hash2 в функции random при вызове gethash(md5($password)). почему ??