A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: add basic password rule validation
thecodrr2b1938dddb6e
diff --git a/apps/web/src/components/dialogs/signupdialog.js b/apps/web/src/components/dialogs/signupdialog.jsindex 4dd321bfb..16815b669 100644--- a/apps/web/src/components/dialogs/signupdialog.js+++ b/apps/web/src/components/dialogs/signupdialog.js@@ -87,6 +87,7 @@ function SignUpDialog(props) {name="password"type="password"autoComplete="new-password"+ validatePasswordsx={{ mt: 1 }}/>{error && <Text variant="error">{error}</Text>}diff --git a/apps/web/src/components/field/index.js b/apps/web/src/components/field/index.jsindex 059e5f3cc..57284285a 100644--- a/apps/web/src/components/field/index.js+++ b/apps/web/src/components/field/index.js@@ -1,8 +1,31 @@import React, { useState } from "react";-import { Flex } from "rebass";+import { Flex, Text } from "rebass";import { Input, Label } from "@rebass/forms";import * as Icon from "../icons";+const passwordValidationRules = [+ {+ title: "8 characters",+ validate: (password) => password.length >= 8,+ },+ {+ title: "1 lowercase letter",+ validate: (password) => /[a-z]/.test(password),+ },+ {+ title: "1 uppercase letter",+ validate: (password) => /[A-Z]/.test(password),+ },+ {+ title: "1 digit",+ validate: (password) => /\d/.test(password),+ },+ {+ title: "1 special character",+ validate: (password) => /\W/.test(password),+ },+];+function Field(props) {const {id,@@ -21,8 +44,10 @@ function Field(props) {inputRef,defaultValue,placeholder,+ validatePassword,} = props;const [isPasswordVisible, setIsPasswordVisible] = useState(false);+ const [rules, setRules] = useState(passwordValidationRules);return (<Flex sx={sx} flexDirection="column">@@ -53,7 +78,17 @@ function Field(props) {placeholder={placeholder}autoComplete={autoComplete}type={type || "text"}- onChange={onChange}+ onChange={(e) => {+ if (validatePassword) {+ const value = e.target.value;+ setRules((rules) =>+ rules.map((rule) => {+ return { ...rule, isValid: rule.validate(value) };+ })+ );+ }+ if (onChange) onChange(e);+ }}onKeyUp={onKeyUp}onKeyDown={onKeyDown}/>@@ -71,6 +106,7 @@ function Field(props) {top: 0,bottom: 0,px: 1,+ cursor: "pointer",borderRadius: "default",":hover": { bg: "border" },}}@@ -91,6 +127,7 @@ function Field(props) {position: "absolute",right: "2px",top: "2px",+ cursor: "pointer",bottom: "2px",px: 1,borderRadius: "default",@@ -101,6 +138,22 @@ function Field(props) {</Flex>)}</Flex>+ {validatePassword && (+ <Flex flexDirection="column" mt={1}>+ {rules.map((rule) => (+ <Flex>+ {rule.isValid ? (+ <Icon.Check color="success" size={14} />+ ) : (+ <Icon.Cross color="error" size={14} />+ )}+ <Text fontSize="body" ml={1}>+ {rule.title}+ </Text>+ </Flex>+ ))}+ </Flex>+ )}</Flex>);}diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.jsindex d60f0f1f0..486a7a042 100644--- a/apps/web/src/components/icons/index.js+++ b/apps/web/src/components/icons/index.js@@ -59,7 +59,8 @@ export const Star = createIcon(Icons.mdiStar);export const StarOutline = createIcon(Icons.mdiStarOutline);export const Circle = createIcon(Icons.mdiCircle);export const CircleEmpty = createIcon(Icons.mdiCircleOutline);-export const Check = createIcon(Icons.mdiCheckCircleOutline);+export const Check = createIcon(Icons.mdiCheck);+export const Cross = createIcon(Icons.mdiClose);export const MoreVertical = createIcon(Icons.mdiDotsVertical);export const Trash = createIcon(Icons.mdiTrashCanOutline);export const Search = createIcon(Icons.mdiMagnify);