From 5953fae6ab328b60d2eb8c573a745ba77e265b2e Mon Sep 17 00:00:00 2001 From: Zhe Li Date: Thu, 8 Jul 2021 15:03:25 +0800 Subject: [PATCH 1/3] Add password policy --- _locales/en/messages.json | 3 +++ manifests/schema-chrome.json | 10 ++++++++++ package-lock.json | 2 +- src/components/Popup/SetPasswordPage.vue | 21 +++++++++++++++++++++ src/store/Menu.ts | 2 ++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 0481f9d6f..0c96968ec 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -389,5 +389,8 @@ }, "backup_file_info": { "message": "Backup your data to a file." + }, + "password_policy_default_hint": { + "message": "The password doesn't meet the security requirements. Contact with your administrator." } } diff --git a/manifests/schema-chrome.json b/manifests/schema-chrome.json index b71a67a60..60dcc98a6 100644 --- a/manifests/schema-chrome.json +++ b/manifests/schema-chrome.json @@ -35,6 +35,16 @@ "title": "Enforce autolock", "description": "If any value is set, then the user will not be able to change the autolock setting. Set to a number in minutes.", "type": "number" + }, + "passwordPolicy": { + "title": "Password policy", + "description": "A regular expression to test if the password meets the security requirements", + "type": "string" + }, + "passwordPolicyHint": { + "title": "Password policy hint", + "description": "Hint to show if the password doesn't meet the security requirements", + "type": "string" } } } diff --git a/package-lock.json b/package-lock.json index d72fab411..3b1c96316 100644 --- a/package-lock.json +++ b/package-lock.json @@ -403,7 +403,7 @@ }, "@types/filewriter": { "version": "0.0.28", - "resolved": "http://registry.npm.taobao.org/@types/filewriter/download/@types/filewriter-0.0.28.tgz", + "resolved": "https://registry.npmjs.org/@types/filewriter/-/filewriter-0.0.28.tgz", "integrity": "sha1-wFTor02d11205jq8dviFFocU1LM=", "dev": true }, diff --git a/src/components/Popup/SetPasswordPage.vue b/src/components/Popup/SetPasswordPage.vue index 1b795d147..502d3fcd4 100644 --- a/src/components/Popup/SetPasswordPage.vue +++ b/src/components/Popup/SetPasswordPage.vue @@ -35,6 +35,20 @@ export default Vue.extend({ enforcePassword: function () { return this.$store.state.menu.enforcePassword; }, + passwordPolicy: function () { + try { + return new RegExp(this.$store.state.menu.passwordPolicy); + } catch { + console.warn( + "Invalid password policy. The password policy is not a valid regular expression.", + this.$store.state.menu.passwordPolicy + ); + return null; + } + }, + passwordPolicyHint: function () { + return this.$store.state.menu.passwordPolicyHint; + }, }, methods: { async removePassphrase() { @@ -49,6 +63,13 @@ export default Vue.extend({ return; } + if (this.passwordPolicy && !this.passwordPolicy.test(this.phrase)) { + const hint = + this.passwordPolicyHint || this.i18n.password_policy_default_hint; + this.$store.commit("notification/alert", hint); + return; + } + if (this.phrase !== this.confirm) { this.$store.commit("notification/alert", this.i18n.phrase_not_match); return; diff --git a/src/store/Menu.ts b/src/store/Menu.ts index 6cf83d52a..c73010255 100644 --- a/src/store/Menu.ts +++ b/src/store/Menu.ts @@ -18,6 +18,8 @@ export class Menu implements Module { enforceAutolock: await ManagedStorage.get("enforceAutolock"), storageArea: await ManagedStorage.get("storageArea"), feedbackURL: await ManagedStorage.get("feedbackURL"), + passwordPolicy: await ManagedStorage.get("passwordPolicy"), + passwordPolicyHint: await ManagedStorage.get("passwordPolicyHint"), }, mutations: { setZoom: (state: MenuState, zoom: number) => { From e79cca31c07b2cef2a2d0f6a814d55999d7afd7d Mon Sep 17 00:00:00 2001 From: Zhe Li Date: Sun, 18 Jul 2021 10:56:46 +0800 Subject: [PATCH 2/3] Update _locales/en/messages.json Co-authored-by: mymindstorm --- _locales/en/messages.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 27405de9d..ff33ce7d6 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -391,7 +391,8 @@ "message": "Backup your data to a file." }, "password_policy_default_hint": { - "message": "The password doesn't meet the security requirements. Contact with your administrator." + "message": "Your password does not meet your organization's security requirements. Contact your administrator for more information." + }, "advisor": { "message": "Advisor" }, From 3701397ebc6168905cf90b8c3809ee510a108d20 Mon Sep 17 00:00:00 2001 From: Zhe Li Date: Sun, 22 Aug 2021 02:02:40 +0800 Subject: [PATCH 3/3] update schema --- manifests/schema-chrome.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/schema-chrome.json b/manifests/schema-chrome.json index 60dcc98a6..a18ba98c6 100644 --- a/manifests/schema-chrome.json +++ b/manifests/schema-chrome.json @@ -38,12 +38,12 @@ }, "passwordPolicy": { "title": "Password policy", - "description": "A regular expression to test if the password meets the security requirements", + "description": "A regular expression to test if the password meets the security requirements. No slashes are needed (e.g. use [A-Z]+, but not use /[A-Z]+/).", "type": "string" }, "passwordPolicyHint": { "title": "Password policy hint", - "description": "Hint to show if the password doesn't meet the security requirements", + "description": "Hint to show if the password doesn't meet the security requirements.", "type": "string" } }