{"id":10,"date":"2008-03-26T14:41:26","date_gmt":"2008-03-26T20:41:26","guid":{"rendered":"http:\/\/xux.in\/blog\/post\/php-generate-random-passwords\/"},"modified":"2021-06-19T19:48:53","modified_gmt":"2021-06-20T01:48:53","slug":"php-generate-random-passwords","status":"publish","type":"post","link":"http:\/\/xux.in\/blog\/post\/php-generate-random-passwords\/","title":{"rendered":"PHP Generate Random Passwords"},"content":{"rendered":"<p>This is a small script written in <a href=\"http:\/\/www.php.net\">PHP<\/a> which will help you to generate N passwords of N length in less than 1ms \ud83d\ude1b<\/p>\n<p>Make sure you have PHP installed, then copy this code to a file called randompass.php<\/p>\n<pre lang=\"php\">#!\/usr\/bin\/php -q\n&lt;?\n\/\/ no i,l,o keep passwords easy\n$chars = \"abcdefghjkmnpqrstuvwxyz0123456789\";\n$passlen = (intval($argv[1])? intval($argv[1]):6);\n$passnum = (intval($argv[2])? intval($argv[2]):1);\n\necho \"Generating $passnum passwords of $passlen letters\/numbers\\n\";\n\/\/ feed the random God :P\nsrand(((int)((double)microtime()*1000003)));\n\nfor ($i=1;$i&lt;=$passnum;$i++) _gen_pass();\n\nfunction _gen_pass() {\n  global $chars, $passlen;\n  $cnt = 1;\n  while ($cnt &lt;= $passlen) {\n    $myrand = rand() % 33;\n    $tmp = substr($chars, $myrand, 1);\n    if (rand(0,1)) $tmp = strtoupper($tmp);\n    $pass = $pass . $tmp;\n    $cnt++;\n  }\n  echo $pass . \"\\n\";\n}\n\n?&gt;\n<\/pre>\n<p>Now you have the file don&#8217;t forget to make it executable:<\/p>\n<pre lang=\"bash\">chmod +x randompass.php<\/pre>\n<p>How it works? See some examples:<\/p>\n<pre lang=\"bash\">Usage: .\/randompass.php [password_length] [password_number]\n\n# The default execution will drop 1 password of 6 letters\/numbers\n.\/randompass.php\nGenerating 1 passwords of 6 letters\/numbers\n9hBEq1\n\n# want 5 passwords of 12 letters\/numbers ?\n.\/randompass.php 12 5\nGenerating 5 passwords of 12 letters\/numbers\nug5Tj8fP3w26\nTn9fnSjy2PmJ\nNRqC6m8J0svn\nYFQ6g3WnHH8r\nds56SnQvsBEq\n<\/pre>\n<p>That&#8217;s all, use it for what you need, don&#8217;t try to break it or find stupid <strong>bugs<\/strong> \ud83d\ude1b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a small script written in PHP which will help you to generate N passwords of N length in less than 1ms \ud83d\ude1b Make sure you have PHP installed, then copy this code to a file called randompass.php #!\/usr\/bin\/php -q &lt;? \/\/ no i,l,o keep passwords easy $chars = &#8220;abcdefghjkmnpqrstuvwxyz0123456789&#8221;; $passlen = (intval($argv[1])? intval($argv[1]):6); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,8,5],"tags":[21,15,16],"class_list":["post-10","post","type-post","status-publish","format-standard","hentry","category-code","category-linux","category-software","tag-password","tag-php","tag-snippet"],"_links":{"self":[{"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/posts\/10","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/comments?post=10"}],"version-history":[{"count":3,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/posts\/10\/revisions"}],"predecessor-version":[{"id":154,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/posts\/10\/revisions\/154"}],"wp:attachment":[{"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/media?parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/categories?post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/tags?post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}