{"id":112,"date":"2009-10-14T13:09:57","date_gmt":"2009-10-14T19:09:57","guid":{"rendered":"http:\/\/rrbits.com\/epb\/2009\/10\/14\/php-random-password-oneliner\/"},"modified":"2011-02-06T17:40:00","modified_gmt":"2011-02-06T23:40:00","slug":"php-random-password-oneliner","status":"publish","type":"post","link":"https:\/\/rrbits.com\/epb\/2009\/10\/14\/php-random-password-oneliner\/","title":{"rendered":"PHP: Random Password Oneliner"},"content":{"rendered":"<p>I am exceedingly lazy, so I made a one-liner random password generator.<\/p>\n<p>How it works: Creates an md5 from a random string, packs this into binary representation, base64 encodes that, strips some of the characters used by base64 (most importantly the = that are typically at the end), and then limits it to 8 characters.  It&#8217;s been broken out here on several lines to make modifying it a bit easier.<\/p>\n<p>(Could make longer passwords by changing what&#8217;s allowed and providing more text to base64_encode or hexadecimal to pack.)<\/p>\n<pre><code>$randpw = substr(\r\n   preg_replace('\/[^a-zA-Z0-9\\.\\-!\\$]\/', '',\r\n      base64_encode(\r\n         pack('H*', md5(time().rand()))\r\n      )\r\n   ), 0, 8);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I am exceedingly lazy, so I made a one-liner random password generator. How it works: Creates an md5 from a random string, packs this into binary representation, base64 encodes that, strips some of the characters used by base64 (most importantly the = that are typically at the end), and then limits it to 8 characters&#8230;.  <a class=\"excerpt-read-more\" href=\"https:\/\/rrbits.com\/epb\/2009\/10\/14\/php-random-password-oneliner\/\" title=\"ReadPHP: Random Password Oneliner\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[122,4262],"class_list":["post-112","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-code","tag-php"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/posts\/112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/comments?post=112"}],"version-history":[{"count":4,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/posts\/112\/revisions"}],"predecessor-version":[{"id":279,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/posts\/112\/revisions\/279"}],"wp:attachment":[{"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/media?parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/categories?post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/tags?post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}