Last active
April 2, 2024 22:36
-
-
Save Niduroki/bf650ed72deb95f628d944fab2193107 to your computer and use it in GitHub Desktop.
Generate German ID Card Numbers, now also in Javascript https://jsfiddle.net/wntmj0vu/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Perso-Nummer Generator</h1> | |
Geburtsdatum:<br> | |
<input id="dob"> (Format: YYMMDD, also 01.02.1989 = 890201)<br> | |
Perso gültig bis:<br> | |
<input id="bbf"> (Format: YYMMDD, also 01.02.2025 = 250201)<br> | |
<a href="#" id="fill" onclick="fillnr">Personalausweisnummer erstellen</a><br> | |
<span id="out1" style="font-family: monospace;">...</span><br> | |
<span id="out2" style="font-family: monospace;">...</span><br> | |
<span id="out3" style="font-family: monospace;">...</span> | |
<hr> | |
Empfohlener Lesestoff: <a href="https://www.damm-legal.de/bgh-die-abfrage-von-einer-ausweisnummer-oder-postleitzahl-oder-eine-kontoueberweisung-entspricht-keinem-ausreichenden-jugendschutz-bei-einem-altersverifikationssystem">BGH Urteil vom 18.10.2007, Az. I ZR 102/05</a><br> | |
Auszug: Der BGH hat […] entschieden, dass es den jugendschutzrechtlichen Anforderungen auch dann nicht genügt, wenn der Zugriff Jugendlicher […] erst nach Eingabe einer Personal- oder Reisepassnummer möglich ist. | |
<script> | |
function ord(str){return str.charCodeAt(0);} | |
function chr2int(chr) { | |
if (ord(chr) < 60) { | |
return parseInt(chr); | |
} else { | |
return (ord(chr) - 55); | |
} | |
} | |
function randint(min, max) { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
function randintleadingzero(a, b) { | |
var result = randint(a,b); | |
if (result < 10) { | |
result = "0"+ result.toString(); | |
} | |
return result.toString(); | |
} | |
function genchecksum(unchecked) { | |
var numvalues = []; | |
unchecked.split("").forEach(function(singular){ | |
numvalues.push(chr2int(singular)); | |
}); | |
var sum = 0; | |
for (var i=0; i<numvalues.length; i++) { | |
if ((i + 3) % 3 === 0) { | |
sum += (numvalues[i] * 7 % 10); | |
} else if ((i + 2) % 3 === 0) { | |
sum += (numvalues[i] * 3 % 10); | |
} else if ((i + 1) % 3 === 0) { | |
sum += (numvalues[i] % 10); | |
} | |
} | |
return (sum % 10).toString(); | |
} | |
function genpersonr(dob = 0, bbf = 0) { | |
if (dob === 0) { | |
dob = randintleadingzero(30,99)+randintleadingzero(1,12)+randintleadingzero(1,28) | |
} | |
if (bbf === 0) { | |
bbf = randintleadingzero(22,27)+randintleadingzero(1,12)+randintleadingzero(1,28) | |
} | |
var aut = ""; | |
var chars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
for (j = 0; j<9; j++) { | |
aut += chars[randint(0,35)]; | |
} | |
checked = aut + genchecksum(aut) + dob + genchecksum(dob) + bbf + genchecksum(bbf); | |
finalchecksum = genchecksum(checked); | |
return [ | |
aut + genchecksum(aut), | |
dob + genchecksum(dob), | |
bbf + genchecksum(bbf) + "D", | |
finalchecksum, | |
checked + "D" + finalchecksum | |
]; | |
} | |
document.getElementById("fill").onclick = function () { | |
dob = document.getElementById('dob').value; | |
bbf = document.getElementById('bbf').value; | |
if (dob === "") { dob = 0; } | |
if (bbf === "") { bbf = 0; } | |
personr = genpersonr(dob, bbf); | |
document.getElementById('out1').innerText = "IDD<<" + personr[0] + "<<<<<<<<<<<<"; | |
document.getElementById('out2').innerText = personr[1] + "<" + personr[2] + "<<<<<<<<<<" + personr[3]; | |
document.getElementById('out3').innerText = "MUSTERMANN<<MAXIMILIAN<<<<<"; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment