import random, string
def generate_password(length: int=4)-> str:
# add lower case chars
lower = [random.choice(string.ascii_lowercase) for i in range(length)]
# add digit chars
digit = [random.choice(string.digits) for i in range(length)]
# add upper case chars
upper = [random.choice(string.ascii_uppercase) for i in range(length)]
# add symbols
symbol = [random.choice(["!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "-", "+", "=", ".", ",", "?"]) for i in range(length)]
# store random generated lists to a variable
original = lower+digit+upper+symbol
# shuffle stored data in place
random.shuffle(original)
return ''.join(original)
from numpy import array
import random
import string
print("This is a password creator")
print("type 1 for only number password or type 2 for alphabet password or type 0 for mixed password")
y = int(input("enter"))
print("type how many digits of password you want")
x = int(input("enter"))
if y==1:
print("ok you choosed password in number")
for i in range(0,x):
k = random.randint(0,9)
print(k,end="")
elif y == 2:
print("ok you choosed alphabet password")
n = 1
for i in range(x):
randomLowerLetter = chr(random.randint(ord('a'), ord('z')))
randomUpperLetter = chr(random.randint(ord('A'), ord('Z')))
if n%2==0:
print(randomLowerLetter,end="")
elif n%2!=0:
print(randomUpperLetter,end="")
n= n + 1
elif y == 0:
print("ok you choosed mixed password of alphabet and numbers")
n=1
letter = 0
for i in range(x):
randomLowerLetter = chr(random.randint(ord('a'), ord('z')))
randomUpperLetter = chr(random.randint(ord('A'), ord('Z')))
k = random.randint(0,9)
if n%2==0:
print(randomLowerLetter,end="")
if letter +1 != x:
print(k,end="")
letter+=2
else:
letter+=1
elif n%2!=0:
print(randomUpperLetter,end="")
letter+=1
n=n+k
if letter >= x:
break
else:
print("read carefully")
print()
print("thanks")
import random
strong_keys = ["@","#","$","£","π","¥","&","3","¢","3","*","?","!","%","/","G","A","B","F","W","F","H","6","9",":","^","=","|","~","∆"]
def password():
try:
n = int(input('your password contain(type in number) : '))
except:
print('Rerun the program and type in number please')
ans = ""
for i in range(n):
rand = random.choice(strong_keys)
if i == 0:
ans = rand
else:
ans += rand
print('
your password: '+ans+'
')
user = input('if you dont like this?
Type "r" else "q" : ')
if user.lower() == 'r':
password()
else:
quit()
password()
import string
import random
## characters to generate password from
alphabets = list(string.ascii_letters)
digits = list(string.digits)
special_characters = list("!@#$%^&*()")
characters = list(string.ascii_letters + string.digits + "!@#$%^&*()")
def generate_random_password():
## length of password from the user
length = int(input("Enter password length: "))
## number of character types
alphabets_count = int(input("Enter alphabets count in password: "))
digits_count = int(input("Enter digits count in password: "))
special_characters_count = int(input("Enter special characters count in password: "))
characters_count = alphabets_count + digits_count + special_characters_count
## check the total length with characters sum count
## print not valid if the sum is greater than length
if characters_count > length:
print("Characters total count is greater than the password length")
return
## initializing the password
password = []
## picking random alphabets
for i in range(alphabets_count):
password.append(random.choice(alphabets))
## picking random digits
for i in range(digits_count):
password.append(random.choice(digits))
## picking random alphabets
for i in range(special_characters_count):
password.append(random.choice(special_characters))
## if the total characters count is less than the password length
## add random characters to make it equal to the length
if characters_count < length:
random.shuffle(characters)
for i in range(length - characters_count):
password.append(random.choice(characters))
## shuffling the resultant password
random.shuffle(password)
## converting the list to string
## printing the list
print("".join(password))
## invoking the function
generate_random_password()
from random import randint
def create_random_chars(nbr_of_chars):
return "".join(chr(randint(33,126)) for i in range(nbr_of_chars))
print(create_random_chars(10))
# I1CU>E5q;$
import string
import random
## characters to generate password from
characters = list(string.ascii_letters + string.digits + "!@#$%^&*()")
def generate_random_password():
## length of password from the user
length = int(input("Enter password length: "))
## shuffling the characters
random.shuffle(characters)
## picking random characters from the list
password = []
for i in range(length):
password.append(random.choice(characters))
## shuffling the resultant password
random.shuffle(password)
## converting the list to string
## printing the list
print("".join(password))
## invoking the function
generate_random_password()