0
Random Generator
Guys, I need your help! I need to create a program that can generate a password in python but that only contain lowercase letters and numbers, with a length that is decided by the user. How can I do this? Thx
8 Respostas
+ 2
import string
import random
up = string.ascii_uppercase
low = string.ascii_lowercase
nums = string.digits
# you can use punctuation as well
# punc = string.punctuation
all = up + low + nums # + punc
length = input("how many characters? ")
# password = ""
# you can use for loop
#for _ in range(int(length)):
# password +=random.choice(all)
# but I prefer the fastest method
password = "".join(random.sample(all, int(length)))
print(password)
+ 1
I don't know realy but i think a madul does exist
+ 1
U can search on web probably u can find this
Especially pyp maduls
0
You can create a string containing the alphabet and numbers, and then extract an index from it using a random class, and you can use an input for the number desired by the user, and continue with the loop until you reach the desired number of characters. Good luck
0
Yeah, but there is a built-in function in python? Only for making the code a bit shorter. Thx
0
You need string.ascii_lowercase, string.digits [https://docs.python.org/3/library/string.html], concatenate them and use secrets.choice [https://docs.python.org/3/library/secrets.html?highlight=random%20choice#secrets.choice] to select random elements
0
Thanks Benjamin Jürgens