-2

I'm using this library to create a QR code for every newly created user. However, when the QR code is generated for each user, it's difficult to differentiate between the two when two users are created. In other words, the QR codes look too similar. How can I generate QR codes that are distinct from each other and not familiar to others?

signals.py:

@receiver(post_save, sender=User)
def create_account(sender, instance, created, **kwargs):
    if created:
        random_number = ''.join(random.choices(string.digits, k=20))
        
        
        img = qrcode.make('cullize')
        
        # Define the directory where the image should be saved within the 'media' folder
        img_dir = os.path.join(settings.MEDIA_ROOT, 'qrcode')
        os.makedirs(img_dir, exist_ok=True)  # Create the directory if it doesn't exist
        
        # Define the complete path to save the image
        img_path = os.path.join(img_dir, 'default.png')
        
        # Save the QR code image
        img.save(img_path)
        
        Account.objects.create(
            user=instance,
            qr_code=os.path.relpath(img_path, settings.MEDIA_ROOT),
            account_id=random_number
        )

The qrcode: enter image description here enter image description here

I'm following this tutorial.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 1
    If you want to visually distinguish them, you could add in error correcting, so that you can paste a small image or piece of text in the middle or something like that, which blocks data but with the error correcting redundancy, the QR code can still be scanned. Or maybe you can just put text at the bottom of each one? Many options. It seems like you're more looking for ideas than actual code though. This is a site to get help with writing code. I can offer suggestions for what to do but maybe it would be better to have a solution in mind, try that, and ask here if you get stuck. – Random Davis Aug 29 '23 at 15:18
  • 2
    Why would you need to have them looking different ? the goal should be to just be able to read it from a camera ? not the human eye? Maybe it you try to change error_correction you could obtain bigger or more different qrcodes ? – Ant0ine64 Aug 29 '23 at 15:19
  • Oh, and of course, as @Ant0ine64 said, it doesn't really make sense to need to distinguish QR codes visually. It would help if you explained why you think you have to do that. Otherwise, I will assume that this is an instance of an [XY problem](https://xyproblem.info/); where you want a solution for the wrong way to go about something. – Random Davis Aug 29 '23 at 15:22
  • Conceptually you can place a thumbnail in the center of each QRcode if you ensure there is a minimum redundancy as @RandomDavis has suggested. Check out [How to insert logo in the center of qrcode in Python?](https://stackoverflow.com/questions/45481990/how-to-insert-logo-in-the-center-of-qrcode-in-python) and see if it answers your query – JonSG Aug 29 '23 at 15:23
  • @RandomDavis We aim to develop a "payment app" that enables users to scan a unique "QR code" for processing payments for products purchased at a supermarket. Our goal is to generate distinct "QR codes" for each user to enhance security measures. – Adamu Dee Azare Aug 29 '23 at 15:25
  • @AdamuDeeAzare same question : how do the final differentiate qrcode by eyes ? We can't recognise quickly a qrcode. Maybe at scanning the app should display the scanned username in BIG to make sure it's the right (in this case yeah the user could read a name made out of letter) – Ant0ine64 Aug 29 '23 at 15:28
  • @AdamuDeeAzare You didn't answer the question. Why do users have to visually distinguish their own QR codes? Whose are they distinguishing them from? Wouldn't making them look unique actually have less security, since each one can be more easily traced back to a particular user? Is it the users who want their QR codes to look different from others? If so, why? If not, who wants to be distinguishing them visually, and what purpose does that serve? "Security" doesn't make sense, because if each code looks different, it would be easier for users to trace back to a particular user. – Random Davis Aug 29 '23 at 15:43
  • Does this answer your question? [How to insert logo in the center of qrcode in Python?](https://stackoverflow.com/questions/45481990/how-to-insert-logo-in-the-center-of-qrcode-in-python) – JonSG Aug 29 '23 at 15:46

0 Answers0