Найти - Пользователи
Полная версия: генератор паролей
Начало » Python для новичков » генератор паролей
1
gwaewion
не знаю как реализовать корректную работу программы, когда истины x11 и х12, х11 и 13 или х12 и х13.

#!/usr/bin/env python
import random
import string
def passgen(pw,p1,p2,p3):
while pw != 0:
x = random.choice(string.ascii_lowercase)
y = random.choice(string.ascii_uppercase)
z = random.choice(string.digits)
# b = random.choice('xyz')
if p1 == bool(True):
print(x, end=" ")
elif p2 == bool(True):
print(y, end=" ")
elif p3 == bool(True):
print(z, end=" ")
pw -= 1

x = int(input("enter password lenght: "))

x1 = str(input("lowercase [y/n]: "))
x2 = str(input("uppercase [y/n]: "))
x3 = str(input("digits [y/n]: "))

x11 = x12 = x13 = 0

if x1 == 'y':
x11 = 1
elif x2 == 'y':
x12 = 1
elif x3 == 'y':
x13 = 1
else:
print("nothing to do")

passgen(x,x11,x12,x13)
PooH
Примерно так, под третий питон сами поправите
#!/usr/bin/env python
import random
import string

def passgen(length=12, lowercase=True, uppercase=True, digits=True):
symbols = ''
if lowercase:
symbols += string.ascii_lowercase
if uppercase:
symbols += string.ascii_uppercase
if digits:
symbols += string.digits
if not symbols:
return None
return ''.join(random.choice(symbols) for i in range(length))

x = int(raw_input("enter password lenght: "))
x1 = str(raw_input("lowercase [y/n]: ")) == 'y'
x2 = str(raw_input("uppercase [y/n]: ")) == 'y'
x3 = str(raw_input("digits [y/n]: ")) == 'y'
print passgen(x, x1, x2, x3)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB