diff options
author | Hailey <me@haileyok.com> | 2024-02-06 10:06:25 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-06 10:06:25 -0800 |
commit | a9ab13e5a936c4d917b878bd53f4e536fa8c95f8 (patch) | |
tree | 1f739d6ef6b33849accd1f3bc6780c0704d8e2fd /src/lib | |
parent | b9e00afdb1a5b80b7a440c19af335ffbec1f3753 (diff) | |
download | voidsky-a9ab13e5a936c4d917b878bd53f4e536fa8c95f8.tar.zst |
password flow improvements (#2730)
* add button to skip sending reset code * add validation to reset code * comments * update test id * consistency sneak in - everything capitalized * add change password button to settings * create a modal for password change * change password modal * remove unused styles * more improvements * improve layout * change done button color * add already have a code to modal * remove unused prop * icons, auto add dash * cleanup * better appearance on android * Remove log * Improve error messages and add specificity to function names --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/strings/password.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/lib/strings/password.ts b/src/lib/strings/password.ts new file mode 100644 index 000000000..e7735b90e --- /dev/null +++ b/src/lib/strings/password.ts @@ -0,0 +1,19 @@ +// Regex for base32 string for testing reset code +const RESET_CODE_REGEX = /^[A-Z2-7]{5}-[A-Z2-7]{5}$/ + +export function checkAndFormatResetCode(code: string): string | false { + // Trim the reset code + let fixed = code.trim().toUpperCase() + + // Add a dash if needed + if (fixed.length === 10) { + fixed = `${fixed.slice(0, 5)}-${fixed.slice(5, 10)}` + } + + // Check that it is a valid format + if (!RESET_CODE_REGEX.test(fixed)) { + return false + } + + return fixed +} |