From 318cd9e9872bf77e65f6c475ae1a0cdf3fcd342a Mon Sep 17 00:00:00 2001 From: Daniel Garcia-Briseno Date: Sun, 6 Mar 2022 10:24:33 -0500 Subject: [PATCH] Update password to be at least 8 characters Add description that emojis are supported. Update minimum password length for reset password popup add password utility Update onboarding and reset password views to share password checking code --- src/status_im/constants.cljs | 2 +- src/status_im/subs.cljs | 5 ++-- .../ui/screens/onboarding/password/views.cljs | 13 +++------- src/status_im/utils/password_utils.cljs | 25 +++++++++++++++++++ translations/en.json | 2 +- 5 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 src/status_im/utils/password_utils.cljs diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 0e98f5404759..4dced2fa3f48 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -67,7 +67,7 @@ (def ^:const profile-pictures-visibility-everyone 2) (def ^:const profile-pictures-visibility-none 3) -(def ^:const min-password-length 6) +(def ^:const min-password-length 8) (def ^:const max-group-chat-participants 20) (def ^:const default-number-of-messages 20) (def ^:const default-number-of-pin-messages 3) diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index abcba7c3b75f..e404945101e4 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -32,6 +32,7 @@ [status-im.utils.gfycat.core :as gfycat] [status-im.utils.money :as money] [status-im.utils.security :as security] + [status-im.utils.password-resources :as pass] [status-im.wallet.db :as wallet.db] [status-im.wallet.utils :as wallet.utils] status-im.ui.screens.keycard.subs @@ -2938,9 +2939,9 @@ (and (pos? (count current-password)) (pos? (count new-password)) (pos? (count confirm-new-password)) - (>= (count new-password) 6) + (pass/valid-password new-password) (>= (count current-password) 6) - (= new-password confirm-new-password))}))) + (pass/confirm-password new-password confirm-new-password))}))) (re-frame/reg-sub :bookmarks/active diff --git a/src/status_im/ui/screens/onboarding/password/views.cljs b/src/status_im/ui/screens/onboarding/password/views.cljs index 225b65ddda5f..b8a653e064ec 100644 --- a/src/status_im/ui/screens/onboarding/password/views.cljs +++ b/src/status_im/ui/screens/onboarding/password/views.cljs @@ -5,15 +5,10 @@ [status-im.i18n.i18n :as i18n] [status-im.constants :as const] [status-im.utils.security :as security] + [status-im.utils.password-resources :as pass] [quo.react-native :as rn] [quo.core :as quo])) -(defn validate-password [password] - (>= (count password) const/min-password-length)) - -(defn confirm-password [password confirm] - (= password confirm)) - (defn screen [] (let [password (reagent/atom nil) confirm (reagent/atom nil) @@ -21,8 +16,8 @@ show-error (reagent/atom nil) confirm-ref (atom nil)] (fn [] - (let [valid-password (validate-password @password) - valid-form (confirm-password @password @confirm) + (let [valid-password (pass/validate-password @password) + valid-form (pass/confirm-password @password @confirm) {:keys [recovering?]} @(re-frame/subscribe [:intro-wizard]) on-submit (fn [] (when (not @processing?) @@ -74,7 +69,7 @@ (> (count @password) (count @confirm)) (reset! show-error false) - (not (confirm-password @password @confirm)) + (not (pass/confirm-password @password @confirm)) (reset! show-error true) :else (reset! show-error false)))}]]] diff --git a/src/status_im/utils/password_utils.cljs b/src/status_im/utils/password_utils.cljs new file mode 100644 index 000000000000..7083163b93cf --- /dev/null +++ b/src/status_im/utils/password_utils.cljs @@ -0,0 +1,25 @@ +(ns status-im.utils.password-resources + (:require [status-im.constants :as const])) + +(defn to-numbers [vals] + (map int vals)) + +(defn diff [vals] + (map - (next vals) vals)) + +(defn is-same? [a b] + (= a b)) + +(defn all-same? [word] + (let [first-letter (first word)] + (every? #{first-letter} word))) + +(defn is-sequential? [sequence] + (all-same? (diff (to-numbers sequence)))) + +(defn validate-password [password] + (and (>= (count password) const/min-password-length) + (not (all-same? password)))) + +(defn confirm-password [password confirm] + (= password confirm)) \ No newline at end of file diff --git a/translations/en.json b/translations/en.json index 292d4c6b03a9..8068c51bc0b2 100644 --- a/translations/en.json +++ b/translations/en.json @@ -1013,7 +1013,7 @@ "pairing-please-set-a-name": "Please set a name for your device.", "passphrase": "Passphrase", "password": "Password", - "password-description": "At least 6 characters. Your password protects your keys. You need it to unlock Status and transact.", + "password-description": "At least 8 characters. It may also include unicode characters and emojis. Your password protects your keys. You need it to unlock Status and transact.", "password-placeholder2": "Confirm your password", "password_error1": "Passwords don't match.", "paste": "Paste",