{"id":14,"date":"2015-03-19T19:13:23","date_gmt":"2015-03-19T19:13:23","guid":{"rendered":"http:\/\/dankaufman.org\/WP\/?p=14"},"modified":"2016-01-06T18:06:11","modified_gmt":"2016-01-06T18:06:11","slug":"simple-password-generator","status":"publish","type":"post","link":"https:\/\/www.dankaufman.org\/WP\/?p=14","title":{"rendered":"Simple Password Generator"},"content":{"rendered":"<p><em><span style=\"color: #ff9900;\">Update: 3\/23\/2015- Added special characters. \u00a0Look for orange text to designate new lines in code.<\/span><\/em><\/p>\n<p>A while back I became <span style=\"color: #000000;\">incredibly<\/span> frustrated with my passwords. \u00a0Nothing seemed safe enough and I had a hard time coming up with &#8216;random&#8217; passwords on my own. \u00a0So I wrote this. \u00a0It&#8217;s nothing complex and you can get this up and running in about 5-10 minutes.<\/p>\n<p>The only real functionality is contained in the index.php file and the php\/generator.php file. \u00a0The CSS and JS are mostly for show and for Bootstrapping and, obviously, can easily be modified for your own needs.<\/p>\n<p><span style=\"color: #993300;\">Please note that this is using an out-dated version of Bootstrap. \u00a0You may need to modify the code slightly if you are using Bootstrap v &gt; 3<\/span><\/p>\n<p><a title=\"PassGen\" href=\"http:\/\/dankaufman.org\/passgen\/\" target=\"_blank\">HERE&#8217;S THE WORKING DEMO IF&#8217;N YOU WANT TO SEE IT<\/a><\/p>\n<ol>\n<li>To start,\u00a0<a title=\"PassGen source files\" href=\"http:\/\/dankaufman.org\/passgen\/passgen.zip\" target=\"_blank\">DOWNLOAD THE SOURCE FILES HERE<\/a><\/li>\n<li>So, let&#8217;s get started with the index.php file. \u00a0You can either reference the downloaded version or write up your own interface but the important areas are the input field wherein you specify how many characters you want your password to be:\n<p style=\"padding-left: 30px;\"><span style=\"color: #808080;\">&lt;label for=&#8221;lengthfield&#8221;&gt;NUMBER OF CHARACTERS:&lt;\/label&gt;<\/span><br \/>\n<span style=\"color: #808080;\"> &lt;input type=&#8221;number&#8221; name=&#8221;lengthfield&#8221; id=&#8221;lengthfield&#8221; placeholder=&#8221;10&#8243; \/&gt;&lt;br \/&gt;<br \/>\n<span style=\"color: #ff9900;\">&lt;label&gt;<\/span><br \/>\n<span style=\"color: #ff9900;\"> &lt;input type=&#8221;checkbox&#8221; class=&#8221;checkbox&#8221; id=&#8221;inclSpecChar&#8221; name=&#8221;inclSpecChar&#8221; value=&#8221;yes&#8221; checked&gt; &lt;span class=&#8221;specCharSpan&#8221;&gt;INCLUDE SPECIAL CHARACTERS (&amp;, #, $, *, %, !, @)&lt;\/span&gt;&lt;\/label&gt;<\/span><br \/>\n&lt;div id=&#8221;passwordBlock&#8221; class=&#8221;alert alert-block alert-success fade in hide&#8221;&gt;<br \/>\n&lt;button class=&#8221;close&#8221; type=&#8221;button&#8221; data-dismiss=&#8221;alert&#8221;&gt;\u00d7&lt;\/button&gt;<br \/>\n&lt;h3 class=&#8221;alert-heading&#8221;&gt;HERE IS YOUR AWESOME NEW PASSWORD&lt;\/h3&gt;<br \/>\n&lt;h2 id=&#8221;passHere&#8221;&gt;&lt;\/h2&gt;<br \/>\n&lt;p id=&#8221;copyArea&#8221;&gt;&lt;a id=&#8221;copyToClipBtn&#8221; class=&#8221;btn&#8221;&gt;&lt;\/a&gt;COPY PASSWORD TO CLIPBOARD&lt;\/p&gt;<br \/>\n&lt;\/div&gt;<\/span><\/p>\n<\/li>\n<li>Some sort of a &#8216;submit&#8217; button and the area wherein the password is displayed. Here&#8217;s mine:\n<p style=\"padding-left: 30px;\"><span style=\"color: #808080;\">\u00a0&lt;a class=&#8221;btn btn-warning btn-large btn-success&#8221; id=&#8221;submitBtn&#8221; href=&#8221;#&#8221;&gt;GENERATE PASSWORD&lt;\/a&gt;<\/span><\/p>\n<p><span style=\"padding-left: 30px;\">And here&#8217;s the corresponding code:<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #808080;\">\u00a0 \u00a0 \u00a0$(&#8220;#submitBtn&#8221;).click(event, function(){<\/span><br \/>\n<span style=\"color: #808080;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $.ajax({<\/span><br \/>\n<span style=\"color: #808080;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0url: &#8216;php\/generator.php&#8217;,<\/span><br \/>\n<span style=\"color: #808080;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0type: &#8216;POST&#8217;,<\/span><br \/>\n<span style=\"color: #808080;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0data: {charlength:$(&#8220;#lengthfield&#8221;).val()<span style=\"color: #ff9900;\">, $(&#8220;inclSpecChar&#8221;).val()<\/span>},<\/span><br \/>\n<span style=\"color: #808080;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 success: function( msg ) {<\/span><br \/>\n<span style=\"color: #808080;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0$(&#8220;#passHere&#8221;).text( msg );<\/span><br \/>\n<span style=\"color: #808080;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0$(&#8220;#passwordBlock&#8221;).fadeIn(&#8216;fast&#8217;);<\/span><br \/>\n<span style=\"color: #808080;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }, \u00a0\/\/end on success<\/span><br \/>\n<span style=\"color: #808080;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 error: function( msg ){<\/span><br \/>\n<span style=\"color: #808080;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0alert(&#8216;Failed to generate password. Please try again.\\r\\nError: &#8216;+msg);<\/span><br \/>\n<span style=\"color: #808080;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}\/\/end on fail<\/span><br \/>\n<span style=\"color: #808080;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 });\/\/end ajax call<\/span><br \/>\n<span style=\"color: #808080;\"> });\/\/end on submit click<\/span><\/p>\n<\/li>\n<li>Lastly, here&#8217;s the PHP that generates the password:\n<p style=\"padding-left: 30px;\"><span style=\"color: #808080;\"><br \/>\n<code>$length = $_POST['charlength'];<br \/>\nif(!$length){<br \/>\n$length = 10;<br \/>\n}<br \/>\n<span style=\"color: #ff9900;\">if($_POST['inclSpecChar']=='yes'){<\/span><br \/>\n<span style=\"color: #ff9900;\"> $vowels = htmlspecialchars('aeuyAEUY&amp;$#*%@!');<\/span><br \/>\n<span style=\"color: #ff9900;\"> } else {<\/span><br \/>\n<span style=\"color: #ff9900;\"> $vowels = 'aeuyAEUY';<\/span><br \/>\n<span style=\"color: #ff9900;\"> }<\/span><br \/>\n$consonants = 'bdghjmnpqrstvzBDGHJLMNPQRSTVWXZ23456789';<br \/>\n$addon = '';<br \/>\n$alt = time() % 2;<br \/>\nfor ($i = 0; $i &lt; $length; $i++) {<br \/>\nif ($alt == 1) {<br \/>\n$addon .= $consonants[(rand() % strlen($consonants))];<br \/>\n$alt = 0;<br \/>\n} else {<br \/>\n$addon .= $vowels[(rand() % strlen($vowels))];<br \/>\n$alt = 1;<br \/>\n}<br \/>\n}<br \/>\necho $addon;<\/code><\/span><\/p>\n<\/li>\n<\/ol>\n<p><!--more--><\/p>\n<p>Yeah, so that&#8217;s pretty much it. \u00a0You could modify this as much as you need but here are the basics. \u00a0The Javascript \/ jQuery sends an Ajax POST request to the PHP file with the inputted value and interprets the return (echo) as the variable &#8216;msg&#8217;. \u00a0The PHP simply takes the specified length specified and spits out a randomly selected string of uppcase\/lowercase letters and numbers.<\/p>\n<h4><span style=\"color: #993300;\">WHAT&#8217;S NEXT?<\/span><\/h4>\n<p>In the next version I&#8217;ll update the Bootstrap and implement special characters (<span style=\"color: #ff9900;\">DONE!<\/span>) so be on the lookout for that. \u00a0Thanks for reading!<\/p>\n<p>Hit me up with any questions or anything.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update: 3\/23\/2015- Added special characters. \u00a0Look for orange text to designate new lines in code. A while back I became incredibly frustrated with my passwords. \u00a0Nothing seemed safe enough and I had a hard time coming up with &#8216;random&#8217; passwords on my own. \u00a0So I wrote this. \u00a0It&#8217;s nothing complex and you can get this &hellip; <a href=\"https:\/\/www.dankaufman.org\/WP\/?p=14\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Simple Password Generator<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.dankaufman.org\/WP\/index.php?rest_route=\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dankaufman.org\/WP\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dankaufman.org\/WP\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dankaufman.org\/WP\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dankaufman.org\/WP\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14"}],"version-history":[{"count":10,"href":"https:\/\/www.dankaufman.org\/WP\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":25,"href":"https:\/\/www.dankaufman.org\/WP\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions\/25"}],"wp:attachment":[{"href":"https:\/\/www.dankaufman.org\/WP\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dankaufman.org\/WP\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dankaufman.org\/WP\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}