{"id":131873,"date":"2022-12-23T21:49:46","date_gmt":"2022-12-24T05:49:46","guid":{"rendered":"http:\/\/vincerosas.net\/?page_id=131873"},"modified":"2022-12-24T00:22:10","modified_gmt":"2022-12-24T08:22:10","slug":"random-password-generator","status":"publish","type":"page","link":"https:\/\/vincerosas.net\/?page_id=131873","title":{"rendered":"Random Password Generator"},"content":{"rendered":"\n<p>I came across this tutorial for building a random password generator. It seemed simple enough and it was. The original code was only about twenty lines I believe. However, since I don&#8217;t like just copying and pasting code and I like to make my stuff more complete, I decided to add in a few things that I learned from another tutorial (a console-based python slot machine) and added in some error checking. Also, since I&#8217;m a firm believer in object-oriented programming, I broke it out into functions and just called the functions at the end. <\/p>\n\n\n\n<iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python\/7def4e1f84?toggleCode=true\" width=\"100%\" height=\"600\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen=\"\"><\/iframe>\n\n\n\n<p>I did notice a couple of unimportant things I had to change because of the way <a rel=\"noreferrer noopener\" href=\"https:\/\/tinket.io\" data-type=\"URL\" data-id=\"https:\/\/tinket.io\" target=\"_blank\">trinket.io<\/a> handles python. I don&#8217;t think they&#8217;re using the latest version as it can&#8217;t handle &#8220;f-strings&#8221;. When I coded this in VS Code on my laptop, I used f-strings since it makes it easy to output variable data with strings without super long concatenated strings. However, the compiler built into the <a rel=\"noreferrer noopener\" href=\"http:\/\/trinket.io\" data-type=\"URL\" data-id=\"trinket.io\" target=\"_blank\">trinket.io<\/a> website didn&#8217;t like that and wouldn&#8217;t run the code. I&#8217;ll post the original code below<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import random\n\nMAX_PWDS = 10\nMIN_PWDS = 1\nMAX_PWD_LENGTH = 10\nMIN_PWD_LENGTH = 4\nNUM_PWDS = 0\nPWD_LENGTH = 0\n\nprint(\"Welcome to the password Generator\")\n\nchars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&amp;*().,;:'\n\n#Gather number of passwords\ndef numPWDS():\n    while True:\n        number = input(f\"Number of passwords to generate ({MIN_PWDS}-{MAX_PWDS}): \")\n        if number.isdigit():\n            number = int(number)\n            if MIN_PWDS &lt;= number &lt;= MAX_PWDS:\n                return(number)\n            else:\n                print(\"Please try again.\")\n        else:\n            print(\"Please enter a number value\")\n\n#Gather password Length\ndef pwdLength():\n    while True:\n        length = input(f\"Length of password(s) ({MIN_PWD_LENGTH}-{MAX_PWD_LENGTH}): \")\n        if length.isdigit():\n            length = int(length)\n            if MIN_PWD_LENGTH &lt;= length &lt;= MAX_PWD_LENGTH:\n                return(length)\n            else:\n                print(\"Please try again.\")\n        else:\n            print(\"Please enter a number value\")\n\n\n#Print results\ndef printPWDS():\n    print(\"Here are your passwords:\")\n    for _ in range(NUM_PWDS):\n        password = \"\"\n        for _ in range(PWD_LENGTH):\n            password += random.choice(chars)\n        print (password)\n\n#Call and run programs\nNUM_PWDS = numPWDS()\nPWD_LENGTH = pwdLength()\nprintPWDS()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I came across this tutorial for building a random password generator. It seemed simple enough and it was. The original code was only about twenty lines I believe. However, since I don&#8217;t like just copying and pasting code and I like to make my stuff more complete, I decided to add in a few things [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":9634,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-131873","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/vincerosas.net\/index.php?rest_route=\/wp\/v2\/pages\/131873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vincerosas.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/vincerosas.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/vincerosas.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vincerosas.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=131873"}],"version-history":[{"count":2,"href":"https:\/\/vincerosas.net\/index.php?rest_route=\/wp\/v2\/pages\/131873\/revisions"}],"predecessor-version":[{"id":131903,"href":"https:\/\/vincerosas.net\/index.php?rest_route=\/wp\/v2\/pages\/131873\/revisions\/131903"}],"up":[{"embeddable":true,"href":"https:\/\/vincerosas.net\/index.php?rest_route=\/wp\/v2\/pages\/9634"}],"wp:attachment":[{"href":"https:\/\/vincerosas.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=131873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}