-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Password validation with zxcvbn (#42)
* add password validation via zxcvbn * lazy load options * fix imports * clean up if statement * prettier
- Loading branch information
Showing
17 changed files
with
166 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { z } from "zod"; | ||
import { zxcvbn, zxcvbnOptions } from "@zxcvbn-ts/core"; | ||
import { loadOptions } from "$lib/zxcvbn"; | ||
|
||
await loadOptions().then((options) => zxcvbnOptions.setOptions(options)); | ||
|
||
const passwordZxcvbn = z.string().refine((pass) => zxcvbn(pass).score > 2, { | ||
message: "Password must be at least 'moderate'" | ||
}); | ||
|
||
export const signupSchema = z.object({ | ||
name: z.string().trim().min(1, "Name must not be blank"), | ||
username: z.string().trim().min(1, "Username must not be blank"), | ||
email: z.string().email(), | ||
password: passwordZxcvbn, | ||
tokenId: z.string().optional() | ||
}); | ||
|
||
export const loginSchema = z.object({ | ||
username: z.string().trim().min(1, "Username must not be blank"), | ||
password: z.string().min(1, "Password must not be blank") | ||
}); | ||
|
||
export const resetPasswordSchema = z.object({ | ||
oldPassword: z.string().min(1), | ||
newPassword: passwordZxcvbn | ||
}); | ||
|
||
export const settingSchema = z.object({ | ||
enableSignup: z.coerce.boolean().default(false), | ||
enableSuggestions: z.coerce.boolean().default(false), | ||
suggestionMethod: z.enum(["surprise", "auto-approval", "approval"]).default("approval"), | ||
enableSMTP: z.coerce.boolean().default(false), | ||
smtpHost: z.string().optional(), | ||
smtpPort: z.coerce.number().optional(), | ||
smtpUser: z.string().optional(), | ||
smtpPass: z.string().optional(), | ||
smtpFrom: z.string().optional(), | ||
smtpFromName: z.string().optional() | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const loadOptions = async () => { | ||
const zxcvbnCommonPackage = await import("@zxcvbn-ts/language-common"); | ||
const zxcvbnEnPackage = await import("@zxcvbn-ts/language-en"); | ||
|
||
return { | ||
dictionary: { | ||
...zxcvbnCommonPackage.default.dictionary, | ||
...zxcvbnEnPackage.default.dictionary | ||
}, | ||
graphs: zxcvbnCommonPackage.default.adjacencyGraphs, | ||
translations: zxcvbnEnPackage.default.translations | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters