- VBNet 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| Resources/ICON | ||
| Sources | ||
| .gitattributes | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
| Settings | ||
tsPwGen
Cryptographically generated passwords whose strength you already know before you generate them.
Five templates yield a recipe: a PwGenOptions instance you build once and hand to Generate, independent of the last call. Depending on the template, that same object returns random characters or a whole passphrase.
Features
- Entropy belongs to the recipe, not the password. Check it before anything is drawn - the same recipe always returns the same number, and a
Generatein between changes nothing. - Cryptographically secure by default, not an option for later. Every draw goes through a CSPRNG (
BCryptGenRandom) unless you plug in your ownRandomSource. - One recipe, one call.
PwGenOptionsis a factory -Alphanumeric,Complex,Passphrase,Pin,Hexeach return a fresh, independent instance, so nothing you set on one call leaks into the next. - Generate never throws. An invalid recipe gives you
""and aPwGenErroryou inspect on your own terms -Code,Message,Origin- or a plainBooleanfromTryGenerate. - Lookalikes out by default. On
AlphanumericandComplex,0/Oand1/l/Iare excluded unless you say otherwise.Pinkeeps them, and so does a setAlphabet(includingHex). - Passphrases at full strength. 8192 words per built-in list - five words are exactly 65 bits, checkable by hand - English or German, or bring your own list.
Examples
Simple
One call, a password. Generate with no arguments is the alphanumeric default - that is the whole default path:
Dim pw As String = PwGen.Generate()
Debug.Print pw ' e.g. tK7mN3pQ8wRx4sYh
A little more
Same call shape, different recipes. A vault password whose bits you check first, a passphrase, a hex token:
' Vault password - grow Length until the recipe has 100 bits
Dim vault As PwGenOptions = PwGenOptions.Alphanumeric
Do While (PwGen.Entropy(vault) < 100 AndAlso vault.Length < PwGen.PWGEN_MAX_LENGTH)
vault.Length += 1
Loop
Dim pw As String
If PwGen.TryGenerate(pw, vault) Then
Debug.Print pw ' e.g. tK7mN3pQ8wRx4sYhK2
End If
' Passphrase - five English words, exactly 65 bits
Dim phrase As PwGenOptions = PwGenOptions.Passphrase
Debug.Print PwGen.Generate(phrase) ' e.g. sail-copper-apple-orbit-maple
' API token - 32 hex characters, 128 bits
Debug.Print PwGen.Generate(PwGenOptions.Hex) ' e.g. a3f10c8e91b2467d0e5a12c9f8b3d047
Recipe first, draw second, never the other way round: Recipes turns one of five templates into a PwGenOptions instance whose entropy you can read before anything is generated. Passwords from Random Characters and Passphrases draw from that same object - only Mode decides whether it hands out characters or whole words - and the result either comes back as a password or leaves a PwGenError you inspect on your own terms, TryGenerate if you'd rather read a Boolean. The CSPRNG and the shuffle underneath are covered in How It Works. They just don't happen to show up in this example.
Installation
Inside the twinBASIC IDE: Project -> References... (Ctrl+T) -> tab Available Packages
Search there for tsPwGen -> check it -> Apply Changes.
The package is MIT-licensed, and the name carries the initials ts of its developer, Thomas Stiller.
The repository lives on a home server: git.thosti.dev/th.stiller/tsPwGen. The first request can take a little longer.
Documentation | Back to the top
tsPwGen (Deutsch)
Kryptografisch sicher erzeugte Kennwörter, deren Stärke du schon vor dem Erzeugen kennst.
Fünf Vorlagen liefern ein Rezept: eine PwGenOptions-Instanz, die du einmal baust und an Generate weiterreichst, unabhängig vom letzten Aufruf. Je nach Vorlage liefert dasselbe Objekt Zufallszeichen oder eine ganze Passphrase.
Merkmale
- Entropie gehört zum Rezept, nicht zum Kennwort. Prüfe sie, bevor überhaupt etwas gezogen wird - dasselbe Rezept liefert immer dieselbe Zahl, ein
Generatedazwischen ändert daran nichts. - Kryptografisch sicher per Default, keine Option für später. Jeder Zug läuft über einen CSPRNG (
BCryptGenRandom), außer du setzt eine eigeneRandomSourceein. - Ein Rezept, ein Aufruf.
PwGenOptionsist eine Fabrik -Alphanumeric,Complex,Passphrase,Pin,Hexliefern jeweils eine frische, unabhängige Instanz, sodass nichts aus einem Aufruf in den nächsten durchsickert. - Generate wirft nie. Ein ungültiges Rezept liefert
""und einenPwGenError, den du in Ruhe auswertest -Code,Message,Origin- oder gleich einenBooleanvonTryGenerate. - Verwechsler sind per Default draußen. Bei
AlphanumericundComplexsind0/Ound1/l/Iausgeschlossen, sofern du nichts anderes sagst.Pinbehält sie, ein gesetztesAlphabet(also auchHex) ebenfalls. - Passphrasen mit voller Stärke. 8192 Wörter pro eingebauter Liste - fünf Wörter sind exakt 65 Bit, von Hand nachrechenbar - Englisch oder Deutsch, oder deine eigene Liste.
Beispiele
Einfach
Ein Aufruf, ein Kennwort. Generate ohne Argumente ist der alphanumerische Default - das ist der ganze Default-Weg:
Dim pw As String = PwGen.Generate()
Debug.Print pw ' z.B. tK7mN3pQ8wRx4sYh
Etwas mehr
Derselbe Aufruf, verschiedene Rezepte. Ein Tresor-Kennwort, dessen Bits du zuerst prüfst, eine Passphrase, ein Hex-Token:
' Tresor-Kennwort - Length erhöhen, bis das Rezept 100 Bit hat
Dim vault As PwGenOptions = PwGenOptions.Alphanumeric
Do While (PwGen.Entropy(vault) < 100 AndAlso vault.Length < PwGen.PWGEN_MAX_LENGTH)
vault.Length += 1
Loop
Dim pw As String
If PwGen.TryGenerate(pw, vault) Then
Debug.Print pw ' z.B. tK7mN3pQ8wRx4sYhK2
End If
' Passphrase - fünf deutsche Wörter, exakt 65 Bit
Dim phrase As PwGenOptions = PwGenOptions.Passphrase
phrase.Wordlist = pgwGerman
Debug.Print PwGen.Generate(phrase) ' z.B. apfel-anker-garten-honig-insel
' API-Token - 32 Hexzeichen, 128 Bit
Debug.Print PwGen.Generate(PwGenOptions.Hex) ' z.B. a3f10c8e91b2467d0e5a12c9f8b3d047
Erst das Rezept, dann der Zug, nie umgekehrt: Rezepte macht aus einer von fünf Vorlagen eine PwGenOptions-Instanz, deren Entropie du lesen kannst, bevor überhaupt etwas erzeugt wird. Kennwörter aus Zufallszeichen und Passphrasen ziehen aus genau demselben Objekt - nur Mode entscheidet, ob es Zeichen oder ganze Wörter liefert - und das Ergebnis ist entweder ein Kennwort oder ein PwGenError, den du in Ruhe auswertest, TryGenerate wenn dir ein Boolean lieber ist. Der CSPRNG und das Mischen dahinter stehen in Wie es funktioniert. Sie kommen in diesem Beispiel nur zufällig nicht vor.
Installation
In der twinBASIC-IDE: Projekt -> Verweise... (Strg+T) -> Reiter Available Packages
Dort nach tsPwGen suchen -> Häkchen setzen -> Apply Changes.
Das Paket ist MIT-lizenziert und der Name trägt die Initialen ts des Entwicklers Thomas Stiller.
Das Repository liegt auf einem Homeserver: git.thosti.dev/th.stiller/tsPwGen. Der erste Aufruf kann etwas länger dauern.