How To Create Password Generator Using Python



In this post we are going to create a Pytho Application which will generate password for us. For this we are going to use the strig and random modue. At first we are going to generate the chracter using the string module, then we are going to use the random module to generate a paswsword. we will also add a function wich will give us the password for our desirable lenght. 

Here is your code:-




import string
import random

if __name__ == "__main__":
    s1 = string.ascii_lowercase
    # print(s1)
    s2 = string.ascii_uppercase
    # print(s2)
    s3 = string.digits
    # print(s3)
    s4 = string.punctuation
    # print(s4)
    plen = int(input("Enter password length\n")) #Todo1: Handle Gibberish
    s = []
    s.extend(list(s1))
    s.extend(list(s2))
    s.extend(list(s3))
    s.extend(list(s4))
    # print(s)
    # random.shuffle(s)
    # print(s)
    print("Your password is: ")
    print("".join(random.sample(s, plen)))
    # print("".join(s[0:plen]))

Post a Comment

Previous Post Next Post