diff --git a/src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue b/src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue index 52745d4a..d7a35cc2 100644 --- a/src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue +++ b/src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue @@ -96,7 +96,7 @@ const { attrs: secretValidationAttrs } = useValidation({ rules: [ { message: 'Secret should be a base32 string', - validator: (value) => value.match(/^[A-Z234567]+$/), + validator: (value) => value.toUpperCase().match(/^[A-Z234567]+$/), }, { message: 'Please set a secret', diff --git a/src/tools/otp-code-generator-and-validator/otp.service.test.ts b/src/tools/otp-code-generator-and-validator/otp.service.test.ts index f2f5449a..24402db8 100644 --- a/src/tools/otp-code-generator-and-validator/otp.service.test.ts +++ b/src/tools/otp-code-generator-and-validator/otp.service.test.ts @@ -20,12 +20,16 @@ describe('otp functions', () => { expect(hexToBytes('0102030405060708090a0b0c0d0e0f')).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]); }); }); - describe('base32tohex', () => { + describe('base32toHex', () => { it('convert a base32 to hex string', () => { expect(base32toHex('ABCDEF')).to.eql('00443205'); expect(base32toHex('7777')).to.eql('ffff0f'); expect(base32toHex('JBSWY3DPEHPK3PXP')).to.eql('48656c6c6f21deadbeef'); }); + + it('case does not matter', () => { + expect(base32toHex('ABC')).to.eql(base32toHex('abc')); + }); }); describe('generateHOTP', () => { diff --git a/src/tools/otp-code-generator-and-validator/otp.service.ts b/src/tools/otp-code-generator-and-validator/otp.service.ts index 7b8c49ad..f1cb65ee 100644 --- a/src/tools/otp-code-generator-and-validator/otp.service.ts +++ b/src/tools/otp-code-generator-and-validator/otp.service.ts @@ -26,6 +26,7 @@ function base32toHex(base32: string) { const base32Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'; const bits = base32 + .toUpperCase() // Since base 32, we coerce lowercase to uppercase .replace(/=+$/, '') .split('') .map((value) => base32Chars.indexOf(value).toString(2).padStart(5, '0'))