Skip to content

Instantly share code, notes, and snippets.

@daif
Last active February 12, 2017 22:06
Show Gist options
  • Save daif/c226f057ba02da715223a7f31a96b6df to your computer and use it in GitHub Desktop.
Save daif/c226f057ba02da715223a7f31a96b6df to your computer and use it in GitHub Desktop.
search in text file
<?php
// script startup time and memory usage
$mem_usage = memory_get_usage();
$time_usage = microtime(true);
$return = 'FALSE';
$password = '070162';
// get password list file from https://github.com/danielmiessler/SecLists/tree/master/Passwords
/* don't touch the above lines */
/* ------------------------------------------------------------------- */
// open file in reading mode
$fp = fopen('10_million_password_list_top_100000.txt', 'r');
// read file line by line
while (($buffer = fgets($fp)) !== false) {
// compare password with read line , and break the loop if yes
if(trim($buffer) == $password) {
$return = 'TRUE';
break;
}
}
//close file
fclose($fp);
/* ------------------------------------------------------------------- */
/* don't touch the below lines */
echo 'Return: '.$return."<br />\n";
// calculate script time and memory usage
$mem_usage = ((memory_get_usage() - $mem_usage));
$time_usage = (microtime(true) - $time_usage);
if($mem_usage<1024) {
$mem_usage .= ' bytes';
}elseif($mem_usage<1048576) {
$mem_usage = number_format(($mem_usage/1024), 3, '.', '').' kilobytes';
} else {
$mem_usage = number_format(($mem_usage/1048576), 3, '.', '').' megabytes';
}
echo "----------------------<br />\n";
echo 'Memory usage: '.$mem_usage." <br />\n";
echo 'Time speed: '.number_format($time_usage, 3, '.', '')." sec<br />\n";
echo "----------------------<br />\n";
echo 'PHP: '.phpversion()." <br />\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment