Download the PHP package dannyps/ccidadao without Composer
On this page you can find all versions of the php package dannyps/ccidadao. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dannyps/ccidadao
More information about dannyps/ccidadao
Files in dannyps/ccidadao
Package ccidadao
Short Description A class for generating and validating Portuguese Citizen Card (CC aka Cartão de Cidadão) Numbers.
License MIT
Informations about the package ccidadao
CCidadao
CCidadao is a PHP Class used to validate and generate Citizen Card numbers.
How to use
Instalation
CCidadao is available on Packagist! You can install it via Composer, by typing:
$ composer require Dannyps/CCidadao
The class will be auto-loaded by composer. Thus, in order to use it, you need only require 'vendor/autoload.php';
in your PHP script.
Softening the curve
Portuguese Citizen Cards are a complicated subject. They have two check digits, and a weird version control system. Internal variables contain the following fields:
In the example number:
- The version chars represent the version of the document in the following manner:
- ZZ => v1
- ZY => v2
- ZX => v3
- ...
- ZA => v26
- YZ => v27
- etc...
Both
$ccd
and$vcd
can be determined, provided the$num
and$ver/$vcc
are available, respectively.
Moreover, the $ccd
depends solely on the $num
, whereas the $vcd
depends on the $num
and on the $vcc
.
Code Examples
Test code is a good place to start. However, code examples are displayed below for your convenience.
Generating an array of valid CC numbers.
Note: The fact these numbers are valid does not mean they are being used by anyone.
Getting the next version of a CC number
As time goes by, people get new Citizen Cards. However, their numbers are already predestined. Because of the algorithm used, it is possible to foresee all possible numbers. Moreover, we know these numbers are sequential.
Validating a CC number
Motivation
There was an interest in being able to quickly generate valid CC numbers for pentesting reasons. Thus, CCidadao was born. Its applications, however, are more abrangent than that.
Contributing
You are welcome to contribute to the code, as well as to the documentation. You should do so by means of a Pull Request. You may use xDebug to profile the execution and find the less effecient methods.
How does it work?
The algorithms to determine both control digits are available online, in some blogs and similar pages. Testing of this class began with real CC numbers, as this was the only way to make sure the code was developed according to reality.