When is a barcode not a barcode?
Have you ever looked at the back of a driver's license and wondered what that weird looking barcode is? Well, my strange brain is always inquisitive and the other day I was looking at mine and decided to see if I could take a photo of it and get the data from it.
The first thing to do was to work out the format of the barcode. This was where I found that it isn't actually a barcode. It is a special type of pdf called PDF417. PDF417 was developed in 1991 by Dr. Ynjiun P. Wang. I could bore you with the format of PDF417, but really the PDF417 symbol consists of 3 to 90 rows.
So now I knew what I was dealing with, how was I going to pull it apart? First I needed to know if there was a third party library out there that can read PDF417. I was in luck ZXing.NET has a library that can read bar codes. It can also read PDF417!!! Eureka, I was one step closer.
Being a .Net geek I wired up Visual studio. Made a quick console app. Imported the ZXing package and started to play. Oh and to make it more fun I am using .Net 10. So let's dive in...
First the NuGet Packages. Notice I need the ZXing.Net.Binding.Windows.Compatibilty, that's because I'm using .Net 10!!!
Now to the meat of the console app.
I first want to get the text from the "barcode". I will create a method for this.
First I turn the image of my license into a bitmap. Next I set up the ZXing reader and tell it that I want to get a PDF417 symbol. I then try to decode the bitmap of my license. What this does is the ZXing Barcode Reader searched the bitmp to see if it can find a PDF417 symbol. If so it decodes it. Finally it return all the text from the decoded symbol.
Great, we have a decoder method. Now we need to break apart the text from the symbol. Let's create a method for that.
I am going to read each line of the decoded symbol. Notice that I am only interested in lines that start with character D and are at least 3 characters long. That is because these lines contain the juicy data from the license.
So, what are some of the interesting data that we might be interested in?
DAQ - Driver License Number
DBD - Date License Was Issued
DBA - Date License Expires
DAC - First Name
DAD - Middle Name
DCS - Last Name
DBB - Date Of Birth
DAY - Color of Eyes
DAU - Height in Inches - even though the license shows it in feet and inches. Some show it in Height and Inches
DAG - Street Address
DAI - City
DAJ - State
These aren't all of them and note every jurisdiction is the same, but these are the most common. If you want all of them Google AAMVA DL/ID Card Design Standard. So now we have a method to decode the license and one to extract the juicy data let's get some of it.
So, first I decode, then I extract the data and then I grab some of the things I want. So, lets see the result.....
Obviously if I was writing an identity systems I might want to store the driver license number. If so, I would suggest hashing it.
NOW THE DISCLAIMER
In order to use someone's driver license you must first get their permission. Also, only store what you need for your system.
If you have enjoyed this Blog Post please consider making a small Donation by scanning this QR code
or going old school and clicking Here
or going old school and clicking Here
Thanks for viewing my blob post. Hopefully it can be of use to you sometime. If you want the source code for this blog please drop me a line admin@sadold.dad and I will be happy to send it to you. As always if you want me to write a blog on some tech stuff drop me a line.


Comments
Post a Comment