Python Password Generator

Python Random Password Generator

with the help of below code you can get a random combination of alphanumaric + punctuation strong password



import string
import random

s1 = string.ascii_lowercase
# print(s1)
s2 = string.ascii_uppercase
# print(s2)
s3 = string.digits
# print(s3)
s4 = string.punctuation
# print(s4)


while True:
    try:
        plen = int(input("enter password length\n"))
        break
    except ValueError:
        print("Please Enter numeric value")


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(s[0:plen]))

print("".join(random.sample(s,plen)))


with open("Saved_Password.txt","a") as f:
    f.write(str("".join(random.sample(s,plen))))
    f.write("\n")
print("Your password has been saved")

Happy coding :)

Comments

Popular posts from this blog

Python chapter 3

Login Page design using Html and CSS only