Password and QR Code Generator

Password and QR Code Generator

In this tutorial, We are going to implement a Python program. This Python program generates the random password of a given length and also generates the QR code of that password. You can simply scan the QR code to identify the password or see the password. QR code stands for Quick Response code is basically a barcode on steroids. While the barcode holds information horizontally, the QR code does so both horizontally and vertically. This enables the QR code to hold over a hundred times more information.



Let’s take an example:-


Input:-

Enter length of password:10

Give name to QR code: data


Output:-

Your new password is: $1N2z0oX29

the password was saved as QR code image


QR code images :-

Let's code it:-

# Load random and qrcode library. random is used to generate random password according to the given length. qrcode is used to generate the qr code of given data.

import random
import qrcode

# This function is used to generate the password according to the given length.  Then define all the character, number, etc and then add lower alphabets, upper alphabets, numbers and symbols. Then generate the password with length of n_characters.

def generate_password(n_characters):
    lower = 'abcdefhijklmnopqrstuvxxyz'
    upper = 'ABCDEFHIJKLMNNOPQRSTUVXXYZ'
    numbers = '12345678901234567890'
    symbols="#$%&/()=[{]}"
    all_characters = lower + upper + numbers + symbols
    password = ''.join(random.sample(all_characters, n_characters))
    return password
# This function generates the QR code of the given name like if we give the name “demo” so it’ll save the QR code in the local system with name “demo.png”. 
def image_qr(password):
    filename = input('Give name to QR code: ') 
    img = qrcode.make(password)
    img.save(filename + ".png")

# This function takes the length of the password and calls the generate_password() function and generate_password() function returns the random generated password based on the given length.

Then Save the QR code of the generated password in the local machine. You can simply see the password by scanning the QR code. Your password will be saved in the form of encrypted form.

def run():
    characters = int(input( 'Enter length of password:'))
    password = generate_password(characters) 
    image_qr(password)
    print(f'Your new password is: {password}')
    print("the password was saved as QR code image")
# This line is used to call the run() method.
if __name__ == '__main__':
    run()	

You can also do some changes in the program like I am storing password in qrcode. You can store something else like story, paragraph, etc.

Video Tutorial 


I hope you like the post. If you like the post then share and comment. Thank You !!!!!!

1 Comments

If you have any doubts, Please let me know

Post a Comment
Previous Post Next Post