HITENDRA PATEL

AADHAR NUMBER VERIFY WITH PHP (OFFLINE)

Published 4 years ago 2052 Views
image

Hi, we are going to make helper function for PHP, which validate aadhar number off-line.

For that we are using VERHOEFF algorithm, which is recommended by INDIAN Government.

Please check following helper function for more information.

<?php
function aadharValidation($aadharNumber) {
	/*...multiplication table...*/
	$multiplicationTable = [
		[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
		[1, 2, 3, 4, 0, 6, 7, 8, 9, 5],
		[2, 3, 4, 0, 1, 7, 8, 9, 5, 6],
		[3, 4, 0, 1, 2, 8, 9, 5, 6, 7],
		[4, 0, 1, 2, 3, 9, 5, 6, 7, 8],
		[5, 9, 8, 7, 6, 0, 4, 3, 2, 1],
		[6, 5, 9, 8, 7, 1, 0, 4, 3, 2],
		[7, 6, 5, 9, 8, 2, 1, 0, 4, 3],
		[8, 7, 6, 5, 9, 3, 2, 1, 0, 4],
		[9, 8, 7, 6, 5, 4, 3, 2, 1, 0],
	];
	/*...permutation table...*/
	$permutationTable = [
		[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
		[1, 5, 7, 6, 2, 8, 3, 0, 9, 4],
		[5, 8, 0, 3, 7, 9, 6, 1, 4, 2],
		[8, 9, 1, 6, 0, 4, 3, 5, 2, 7],
		[9, 4, 5, 3, 1, 2, 6, 8, 7, 0],
		[4, 2, 8, 6, 5, 7, 3, 9, 0, 1],
		[2, 7, 9, 3, 8, 0, 6, 4, 1, 5],
		[7, 0, 4, 6, 9, 1, 3, 2, 5, 8],
	];
	/*...split aadhar number...*/
	$aadharNumberArr = str_split($aadharNumber);
	/*...check length of aadhar number...*/
	if (count($aadharNumberArr) == 12) {
		/*...reverse aadhar number...*/
		$aadharNumberArrRev = array_reverse($aadharNumberArr);
		$tableIndex         = 0;
		/*...validate...*/
		foreach ($aadharNumberArrRev as $aadharNumberArrKey => $aadharNumberDetail) {
			$tableIndex = $multiplicationTable[$tableIndex][$permutationTable[($aadharNumberArrKey % 8)][$aadharNumberDetail]];
		}
		return ($tableIndex === 0);
	}
	return false;
}

By using this function, if we get TRUE then given aadhar number is valid & if FALSE then wrong aadhar number.

A BLOG ABOUT DEVELOPMENT

Subscribe and get my latest blog post in your inbox.
image
DIGITAL OCEAN SETUP LARAVEL

Install & configure laravel project into live digital ocean server.

image
LARAVEL PUSH NOTIFICATION

Laravel push notification for devices with FCM

image
INSTALL COMPOSER ON MACOS

Install Composer on MacOS