Referrals 0.5.0: Unguessable codes and a grandfathering switch
Referrals 0.5.0 makes generated referral codes hard to predict and adds a switch for invite-only sites: whether accounts that existed before codes became required keep their access.
Codes that cannot be predicted
Generate now draws codes from the system’s cryptographic random source instead of the ordinary random number generator, which was not built to resist someone guessing. Codes are handed out on purpose, including in ?ref=CODE links, so on a site that requires a code a predictable one would be a way in. Code length and characters stay the same, and existing codes keep working.
Grandfather existing users
With Require Referrals on, the settings page now shows Grandfather Existing Users: “Accounts created before referrals became required keep their access. Turn this off and they must enter a code too.” It is on by default, so switching to invite-only does not lock out current users.
The module only stores the choice. PhoenixKit core’s invite-only access gate is what enforces it, and the switch is hidden when the installed core has no such gate, so it never appears without effect.
Upgrading
Referrals 0.5 needs phoenix_kit 1.7.189 or later within 1.7. No migration. If you turn the switch off on a site that requires codes, accounts without a code will be asked for one.
Full release notes: Referrals 0.5.0
0.5.0 · 3 August 2026
Security
- Generated referral codes now come from a CSPRNG.
generate_random_code/0draws from:crypto.strong_rand_bytes/1instead ofEnum.random/1.:randis seeded per process and is not built to resist an observer, and codes are handed out by design (including in?ref=CODElinks) — underreferral_codes_requireda predictable code is a predictable way into the site. The alphabet and length are unchanged, so existing codes keep working. - A compile-time guard now rejects a
@code_alphabetwhose size does not divide 256 evenly, since therem(byte, size)mapping would silently bias toward the low characters and shrink the keyspace. A distribution test covers the runtime half.
Added
- Grandfathering toggle for the invite-only access gate. A new
referral_grandfather_existingsetting (defaulttrue) records whether accounts created before referrals became required keep their access, withgrandfather_existing?/0/set_grandfather_existing/1and a toggle on the referrals settings page. Core’s invite-only access gate is what reads and enforces it — see the “Invite-only access gate” section ofPhoenixKit.Users.Referrals. access_gate_available?/0— whether the installed core actually has that gate. Thephoenix_kitrequirement spans versions from before it existed, so the settings page asks first and hides the grandfathering toggle rather than offering a switch wired to nothing.
Referrals 0.5.0. Install or update: {:phoenix_kit_referrals, "~> 0.5"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.