Skip to main content

How to Make Your Own NRIC Barcode [Python Tutorial]

Website Barcode NRIC logo

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
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
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.

NRIC Barcode Image from Sample Code
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

Popular posts from this blog

How to read barcodes? Find out how they really work.

Barcodes are everywhere, on the packaging of every product sold commercially in stores, on parcels for delivery, and even used for identification on membership cards. They are even used to make payments these days. What exactly is a barcode? A barcode is an image which consists of bars and spaces. This is a very popular method to store data (numerals and characters) in a machine-readable way representation.  History of Barcodes The barcode was created by Norman Joseph Woodland and Bernard Silver and patented in the US in 1951. The creation depended on Morse code that was extended to thin and thick bars.  Barcodes turned out to be monetarily successful when they were utilized to automate supermarket checkout systems, an errand for which they have gotten become almost universal. The Uniform Grocery Product Code Council had picked, in 1973, the barcode configuration created by George Laurer. Laurer's barcode, with vertical bars, printed better than the circular barcode created by Wood

Know when a NRIC number is fake - steps to validate one

With the recent Covid-19 pandemic, the Singapore government has mandated the use of SafeEntry NRIC check-ins to facilitate contact tracing. Before entering any store/ building, everyone is required to register their NRIC number either by the NRIC card, or using the SafeEntry app. This process is called the SafeEntry NRIC check-in. Singapore is the first in the world to implement a country-wide contact tracing system, and many countries have lauded Singapore for her efficiency and quick-thinking. When the mobile app for SafeEntry NRIC check-in was launched, many countries showed interest in the SafeEntry NRIC technology. Because of its prevalent use during this period, you must be wondering... What is a Valid NRIC Number? Is S981234A a valid NRIC number?  What about T9823212Z? The NRIC is used for many purposes in Singapore. While it may seem totally random, there is a actually formula behind how each NRIC number is generated. Here's a quick recap on the algorithm!  The structure of