Example 1: python password generator
import random
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@£$%^&*().,?0123456789'
number = input('Please enter a number of passwords.')
try:
number = int(number)
except:
print("Error, please enter a number!")
length = input('Length of password?')
try:
length = int(length)
except:
print("Error, please enter a number!")
print('\nHere are your password(s):')
for pwd in range(number):
password = ''
for c in range(length):
password += random.choice(chars)
print(password)
Example 2: python random password generator
import random
alph = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz\
1234567890 !@
out = ''
for char in string:
out += random.choice(alph)
print(out)
Example 3: python password generator
import random
import string
x = str(input("Do you want a password? y/n "))
list = []
if x == "y":
print("Alright!")
for i in range(16):
_1 = random.choice(string.ascii_letters)
_2 = random.randint(1, 9)
list.append(_1)
list.append(_2)
else:
print("ok")
def convert(list):
s = [str(i) for i in list]
res = "".join(s)
return(print(res))
convert(list)
Example 4: randomly generated password python
import random
import os
letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', ]
def random_password_generation():
randnum = random.randrange(0, 10)
randletter = random.choice(letters)
if(random.randrange(0,2) == 1):
randletter = randletter.lower()
else:
randletter = randletter.upper()
randnum2 = random.randrange(0, 10)
randletter2 = random.choice(letters)
if(random.randrange(0,2) == 1):
randletter2 = randletter2.lower()
else:
randletter2 = randletter2.upper()
randnum3 = random.randrange(0, 10)
randletter3 = random.choice(letters)
if(random.randrange(0,2) == 1):
randletter3 = randletter3.lower()
else:
randletter3 = randletter3.upper()
randnum4 = random.randrange(0, 10)
randletter4 = random.choice(letters)
if(random.randrange(0,2) == 1):
randletter4 = randletter4.lower()
else:
randletter4 = randletter4.upper()
randnum5 = random.randrange(0, 10)
randletter5 = random.choice(letters)
if(random.randrange(0,2) == 1):
randletter5 = randletter5.lower()
else:
randletter5 = randletter5.upper()
randnum6 = random.randrange(0, 10)
randletter6 = random.choice(letters)
if(random.randrange(0,2) == 1):
randletter6 = randletter6.lower()
else:
randletter6 = randletter6.upper()
randnum7 = random.randrange(0, 10)
randletter7 = random.choice(letters)
if(random.randrange(0,2) == 1):
randletter7 = randletter7.lower()
else:
randletter7 = randletter7.upper()
randnum8 = random.randrange(0, 10)
randletter8 = random.choice(letters)
if(random.randrange(0,2) == 1):
randletter8 = randletter8.lower()
else:
randletter8 = randletter8.upper()
randnum9 = random.randrange(0, 10)
randletter9 = random.choice(letters)
if(random.randrange(0,2) == 1):
randletter9 = randletter9.lower()
else:
randletter9 = randletter9.upper()
randnum10 = random.randrange(0, 10)
randletter10 = random.choice(letters)
if(random.randrange(0,2) == 1):
randletter10 = randletter10.lower()
else:
randletter10 = randletter10.upper()
random_password = (randnum, randletter, randnum2, randletter2, randnum3, randletter3, randnum4, randletter4, randnum5, randletter5, randnum6, randletter6, randnum7, randletter7, randnum8, randletter8, randnum9, randletter9, randnum10, randletter10)
random_password = str(random_password)
print('randomly generated password:', random_password.replace("'", "").replace(" ", "").replace(",", "").replace(",", "").replace(")", "").replace("(", ""))
print(' ')
again_ask()
def again_ask():
again = input('again? y/n: ')
again = again.lower()
if(again == 'y'):
os.system('clear')
random_password_generation()
elif(again == 'n'):
os.system('clear')
print('Ok then.')
exit()
elif(again != 'y' or 'n'):
print(' ')
print('do it propper this time!')
print(' ')
again_ask()
random_password_generation()
again_ask()
Example 5: python random string for password generator
''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(N))