benkeen / generatedata

A powerful, feature-rich, random test data generator.
https://generatedata.com
2.21k stars 610 forks source link

Sugest: New datatype "Personal identification" / "National identification" / "SSN" #147

Open ExequielAD opened 10 years ago

ExequielAD commented 10 years ago

Creation of a new datatype "Personal identification" / "National identification" / "SSN". Country dependant.

We solved modifying Alphanumeric class for the Spanish DNI. It may generate some duplicated values but its enough for our needs

    public function generate($generator, $generationContextData) {
            $formats = explode("|", $generationContextData["generationOptions"]);
            $chosenFormat = $formats[0];
            if (count($formats) > 1) {
                    $chosenFormat = $formats[rand(0, count($formats)-1)];
            }
            if ($chosenFormat=="[[DNI]]"){ // Spanish national identity
                    $chosenFormat="xxxxxxxx"; // 8 digits
                    $isDNI=1;
            }elseif ($chosenFormat=="[[xDNI]]"){ // Spanish Foreign Identification Number
                    $chosenFormat="xxxxxxx";  // 7 digits
                    $isXDNI=1;
                    $isDNI=1;
            }
            $val = Utils::generateRandomAlphanumericStr($chosenFormat);
            if ($isXDNI) { // must add Foriegn Identification Number letter
                    $val = substr("XYZ",rand(0,2),1) . $val;
            }
            if ($isDNI) { // must calculate identity control digit
                    $val .= substr("TRWAGMYFPDXBNJZSQVHLCKE",strtr($val,"XYZ","012")%23,1);
            }
            return array(
                    "display" => $val
            );
    }
twindual commented 10 years ago

I've added a GitHub project called NationalId https://github.com/twindual/NationalId that I'm integrating into my fork of generatedata. Just need some time this weekend to test out the new datatype NationalId before submitting a pull request. Would you mind if I included your code as well?

benkeen commented 10 years ago

Terrific, guys. Yeah, assuming exequial doesn't mind, my preference would be for your single data type, Andre, to group all the national IDs. That would be a very nice addition.