top of page

Random Password Generator

RandPassGen.png

Random Password Generator Python Code Below

#import modules
import string
import random

#store characters in lists
s1 = list(string.ascii_lowercase)
s2 = list(string.ascii_uppercase)
s3 = list(string.digits)
s4 = list (string.punctuation)

#ask user about the number of characters
user_input = input("How many characters do you want in your passsword?\n")

#check this input, is it number? is it more than 8?
while True:
    try:
        characters_number = int(user_input)
        if characters_number < 8:
            print("Your number should be atleast 8!\n")
            user_input = input("Please enter your number again\n")
        else:
            break
        
    except:
        print("Please, enter numbers only")
        user_input = input("How many characters do you want in your password?\n")
        
#shuffle all lists
random.shuffle(s1) 
random.shuffle(s2)      
random.shuffle(s3)      
random.shuffle(s4)

#calculate 30% 20% of number of characters
part1 = round(characters_number * (30/100))
part2 = round(characters_number * (20/100))

#generation of the password (60% letters and 40% digits & punctuations)
result = []

for x in range(part1):
    result.append(s1[x])
    result.append(s2[x])
    
for x in range(part2):
    result.append(s3[x])
    result.append(s4[x])
    
#shuffle result
random.shuffle   (result) 

#join result
password = "".join(result)
print("Strong password: ", password)

Future work will explore possibilities the code to be used for creating an one time sign with bash script

©2022 by Help organisers. Proudly created with Wix.com
Disclaimer: we are not collecting personal data or asking for money from you; please do not share your personal detail unless we ask with the relevant code

bottom of page