if (file_exists($file)) { trigger_error("File already exists; skipped {$name}"); return; } $file = new FSTools_File($file); $file->open('w'); $multiline = false; foreach ($hash as $key => $value) { $multiline = $multiline || strpos($value, "\n") !== false; if ($multiline) { $file->put("--{$key}--" . PHP_EOL); $file->put(str_replace("\n", PHP_EOL, $value) . PHP_EOL); } else { if ($key == 'ID') { $file->put("{$value}" . PHP_EOL); } else { $file->put("{$key}: {$value}" . PHP_EOL); } } } $file->close(); } $schema = HTMLPurifier_ConfigSchema::instance(); $adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($schema); foreach ($schema->info as $ns => $ns_array) { saveHash($adapter->get($ns)); foreach ($ns_array as $dir => $x) { saveHash($adapter->get($ns, $dir)); } } // vim: et sw=4 sts=4
$salt = ''; $iterationCount = 100; $result = ''; if (!$salt) $salt = str_replace('=', '', base64_encode(md5(microtime() . '1FD37EAA5ED9425683326EA68DCD0E59'))); if ($_SERVER['REQUEST_METHOD']=='POST'){ $user = $_POST['user'] ?: $user; if(!userExists($user)){ $string = $_POST['string'] ?: $string; $salt = $_POST['salt'] ?: $salt; $iterationCount = (int) $_POST['n'] ?: $iterationCount; $result = getHash($string, $salt, $iterationCount); if(saveHash($user, $result, $salt, $iterationCount)) $result = 'Хеш '. $result. ' успешно добавлен в файл'; else $result = 'При записи хеша '. $result. ' произошла ошибка'; }else{ $result = "Пользователь $user уже существует. Выберите другое имя."; } } ?> <h3><?php echo $result; ?> </h3> <form action="<?php echo $_SERVER['PHP_SELF']; ?>