Passwords you can measure before you generate.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-06 13:54:32 +02:00
Resources/ICON Publish tsPWGen as a twinBASIC community package with CSPRNG generation, bilingual docs, and tests. 2026-08-15 14:11:13 +02:00
Sources Replace Assert-based tests with the tsJson runner and align the handbook with the finished package. 2026-08-21 16:28:05 +02:00
.gitattributes Publish tsPWGen as a twinBASIC community package with CSPRNG generation, bilingual docs, and tests. 2026-08-15 14:11:13 +02:00
.gitignore Stop tracking IDE package copies and ignore them so the repo keeps only project files. 2026-10-06 13:54:32 +02:00
LICENSE Publish tsPWGen as a twinBASIC community package with CSPRNG generation, bilingual docs, and tests. 2026-08-15 14:11:13 +02:00
README.md Replace Assert-based tests with the tsJson runner and align the handbook with the finished package. 2026-08-21 16:28:05 +02:00
Settings Replace Assert-based tests with the tsJson runner and align the handbook with the finished package. 2026-08-21 16:28:05 +02:00

Zum deutschen Teil


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 Generate in between changes nothing.
  • Cryptographically secure by default, not an option for later. Every draw goes through a CSPRNG (BCryptGenRandom) unless you plug in your own RandomSource.
  • One recipe, one call. PwGenOptions is a factory - Alphanumeric, Complex, Passphrase, Pin, Hex each 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 a PwGenError you inspect on your own terms - Code, Message, Origin - or a plain Boolean from TryGenerate.
  • Lookalikes out by default. On Alphanumeric and Complex, 0/O and 1/l/I are excluded unless you say otherwise. Pin keeps them, and so does a set Alphabet (including Hex).
  • 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 Generate dazwischen ä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 eigene RandomSource ein.
  • Ein Rezept, ein Aufruf. PwGenOptions ist eine Fabrik - Alphanumeric, Complex, Passphrase, Pin, Hex liefern 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 einen PwGenError, den du in Ruhe auswertest - Code, Message, Origin - oder gleich einen Boolean von TryGenerate.
  • Verwechsler sind per Default draußen. Bei Alphanumeric und Complex sind 0/O und 1/l/I ausgeschlossen, sofern du nichts anderes sagst. Pin behält sie, ein gesetztes Alphabet (also auch Hex) 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.


Dokumentation | Nach oben