Ever wanted to create a barcode from your NRIC number? Ever wanted to build a Python program in 2 steps? By the end of this tutorial, you will have made a 2-step NRIC Barcode Generator!
PS: With basic Python skills, the tutorial is fail-proof!
Rationale
As a human being on earth, everyone is issued a unique identification number at birth. Singapore is no exception, and we Singaporeans are labelled with a National Registration Identity Card (NRIC number) number. Non-Singaporeans are also issued a version of NRIC number, called Foreign Identification Number (FIN). The NRIC number is king in Singapore, where it is used to apply for schools, driving tests, army enlistment, HDB residence. From young, the need to memorise these 9 characters has been instilled in us. But sometimes we may forget, or recall our NRIC number incorrectly.
This is how whatismybarcode.blogspot.com is born!
With the advent of technology, there must be a simpler and more accurate way to recall our NRIC number. What if the NRIC number is represented as a barcode? One simply need to store a copy of the barcode on his phone, and scan it with ease at any identification checkpoints.
By the end of this article, you will learn how to make a barcode from your own NRIC number using Python! I chose Python because its code is very readable and its syntax is easy.
Python Programming Language Logo |
Before we start, here's a recap on how a NRIC number works: How to Validate a NRIC Number?
Requirements
Ensure that you have Python3 installed. We will be using a Python module python-barcode. If you have installed pip on your local system, simply install the module using the following command on your terminal:
pip install python-barcode
A success message should appear, similar to the screenshot below
pip install success message on terminal |
Instructions
Before we start proper, let's import the python-barcode module we will be using. Since the NRIC number is alphanumeric, we will use Code 39 barcode type.
from barcode.codex import Code39
Step 1 - Create the Barcode Image
We create the barcode image using an ImageWriter. Since the NRIC number already has its own checksum, we set add_checksum to False. Remember to replace nric variable with your own nric string!
nric = "S9801234A"
code39_barcode = Code39(nric, add_checksum =False,
writer=barcode.writer.ImageWriter())
Step 2 - Save the Barcode
Next, we call the function save() to store the image produced into a .png file. Here, filename is set to "nric_barcode", but feel free to change it!
filename = 'nric_barcode'
code39_barcode.save(filename)
Results
And voila, we are done! The file is saved locally to the same folder as your Python script. This is the barcode from the sample code. Of course, this NRIC number is not valid.
Sample NRIC Barcode Generated Using Python |
Give it a try and comment below how it goes!
Project on a Large Scale
I found a repository on Github which uses the python-barcode package to generate over 10000 NRIC barcode images at a time. The project goal was to prove the ease of generating valid NRIC numbers and their respective barcode images.
The author was intrigued by the news headline: Man arrested, suspected of redeeming more than 200 face masks from vending machines in May 2020 where the Singapore government issued free face masks to all citizens. The collection method was simple - simply scan the NRIC barcode at the barcode reader and the vending machine will dispense a pack of masks. This suggests that the man had actually generated over 200 barcodes by himself.
You can find his repo here: https://github.com/bryanseah234/sgNRIC2003
Conclusion
This post is strictly for educational purpose.
Coupled with the fact that the knowledge to generate valid NRIC number is public, identity theft could be commonplace. The Singapore government has taken active steps to reduce the potential of such crimes. One solution is implementing a 2-Factor Authentication using SingPass/ mobile phone SMS verification. Another action taken was legislating the NRIC number to be protected by the Personal Data Protection Act (PDPA), and it is now illegal to collect NRIC numbers.
I hope this post has been informative! :)
Comments
Post a Comment