Skip to content

Instantly share code, notes, and snippets.

View pmeulen's full-sized avatar

Pieter van der Meulen pmeulen

View GitHub Profile
@pmeulen
pmeulen / SecureRandomPassword.php
Last active August 29, 2015 14:18
Generate a secure random password in the the "Base32" alphabet
<?php
// Generate a secure random password in the the "Base32" alphabet
// Uses openssl secure random function for RNG generation
// Because the set of characters has 32 = 2^5 distinct values, characters can be
// easily selected, without bias (i.e. each character has the same chance
// of being selected), by using 5 bits of randomness per character.
// Note: strlen(base32_alphabet) MUST be exactly 2^bits_per_value