{"id":192,"date":"2026-11-14T21:10:24","date_gmt":"2026-11-14T21:10:24","guid":{"rendered":"https:\/\/cyberstec.com\/?p=192"},"modified":"2026-11-14T21:10:24","modified_gmt":"2026-11-14T21:10:24","slug":"python-password-generator-code","status":"publish","type":"post","link":"https:\/\/cyberstec.com\/index.php\/2026\/11\/14\/python-password-generator-code\/","title":{"rendered":"Python password generator code"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">To run the code inside the terminal type: python <em>filename.py<\/em><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Handy script to generate a random password based on user-defined rules (upper and lower letters, umber of special characters, length,..)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">import secrets<br>import string<br>import random<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lower = string.ascii_lowercase<br>upper = string.ascii_uppercase<br>digits = string.digits<br>special = string.punctuation<br>allChars = lower + upper + digits + special<br>password = &#8220;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">pwLen = int(input(&#8220;How long should the password be? &#8220;))<br>minUpper = int(input(&#8220;Minimum Upper Case: &#8220;))<br>minLower = int(input(&#8220;Minimum Lower Case &#8220;))<br>minDigits = int(input(&#8220;Minimum Numbers: &#8220;))<br>minSpec = int(input(&#8220;Minimum Special: &#8220;))<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">for i in range(minUpper):<br><em>[PRESS TAB]<\/em>password += &#8220;&#8221;.join(random.choice(secrets.choice(upper)))<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">for i in range(minLower):<br><em>[PRESS TAB]<\/em>password += &#8220;&#8221;.join(random.choice(secrets.choice(lower)))<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">for i in range(minDigits):<br><em>[PRESS TAB]<\/em>password += &#8220;&#8221;.join(random.choice(secrets.choice(digits)))<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">for i in range(minSpec):<br><em>[PRESS TAB]<\/em>password += &#8220;&#8221;.join(random.choice(secrets.choice(special)))<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">remaining = pwLen &#8211; minUpper &#8211; minLower &#8211; minDigits &#8211; minSpec<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">for i in range(remaining):<br>password += &#8220;&#8221;.join(random.choice(secrets.choice(allChars)))<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">password = list(password)<br>random.shuffle(password)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">print(&#8220;&#8221;.join(password))<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To run the code inside the terminal type: python filename.py Handy script to generate a random password based on user-defined rules (upper and lower letters, umber of special characters, length,..)&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-192","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/cyberstec.com\/index.php\/wp-json\/wp\/v2\/posts\/192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cyberstec.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cyberstec.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cyberstec.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cyberstec.com\/index.php\/wp-json\/wp\/v2\/comments?post=192"}],"version-history":[{"count":1,"href":"https:\/\/cyberstec.com\/index.php\/wp-json\/wp\/v2\/posts\/192\/revisions"}],"predecessor-version":[{"id":193,"href":"https:\/\/cyberstec.com\/index.php\/wp-json\/wp\/v2\/posts\/192\/revisions\/193"}],"wp:attachment":[{"href":"https:\/\/cyberstec.com\/index.php\/wp-json\/wp\/v2\/media?parent=192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cyberstec.com\/index.php\/wp-json\/wp\/v2\/categories?post=192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cyberstec.com\/index.php\/wp-json\/wp\/v2\/tags?post=192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}