Skip to content

Commit 86870f8

Browse files
fix: making sure that there is always all characters rendered ofr base32
1 parent 33290b2 commit 86870f8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/utils/password-base32.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@ import type { PasswordGenerator, RandomSource } from "@/utils/crypto";
33

44
function toReadableHash(input: Uint8Array) {
55
const c = crockfordBase32.encode(input);
6-
return (c.match(/.{5}/g) ?? []).join("-");
6+
const middle = Math.floor(c.length / 2);
7+
const quart = Math.floor(middle / 2);
8+
const secondQuart = middle + Math.floor((c.length - middle) / 2);
9+
return (
10+
c.substring(0, quart) +
11+
"-" +
12+
c.substring(quart, middle) +
13+
"-" +
14+
c.substring(middle, secondQuart) +
15+
"-" +
16+
c.substring(secondQuart)
17+
);
718
}
819

920
class RandomBase32 implements PasswordGenerator {

0 commit comments

Comments
 (0)