This function creates a registration code with 8 ASCII characters. The aim is to send a user a secret, which can be easily copied by the user into a registration dialog. The secret uses a reduced alphabet of 32 letters and digits. Characters known to be commonly confused by users are removed. The secret is not a password. It is just a personal token to enable the registration in order to prevent annonymous registration attempts.
- pgcrypto: gen_random_bytes
The secret alphabeth has 32 characters. Each character requires 5 bit. A secret with 8 characters reqires 40 bit or 5 byte. The number of different secrets is 2⁴⁰ = 1099511627776.
RND | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
0 | h4 | g4 | f4 | e4 | d4 | c4 | b4 | a4 |
1 | h3 | b3 | f3 | e3 | d3 | c3 | b3 | a3 |
2 | h2 | g2 | f2 | e2 | d2 | c2 | b2 | a2 |
3 | h1 | g1 | f1 | e1 | d1 | c1 | b1 | a1 |
4 | h0 | g0 | f0 | e0 | d0 | c0 | b0 | a0 |
The bits of the characters of the secret are:
CHR | |||||
---|---|---|---|---|---|
1 | a4 | a3 | a2 | a1 | a0 |
2 | b4 | b3 | b2 | b1 | b0 |
3 | c4 | c3 | c2 | c1 | c0 |
4 | d4 | d3 | d2 | d1 | d0 |
5 | e4 | e3 | e2 | e1 | e0 |
6 | f4 | f3 | f2 | f1 | f0 |
7 | g4 | g3 | g2 | g1 | g0 |
8 | h4 | h3 | h2 | h1 | h0 |