Skip to content

Commit 37a8b1f

Browse files
Sneezrymymindstorm
andauthored
Add password policy (#698)
* Add password policy * Update _locales/en/messages.json Co-authored-by: mymindstorm <mymindstorm@evermiss.net> * update schema Co-authored-by: mymindstorm <mymindstorm@evermiss.net>
1 parent 450a4a5 commit 37a8b1f

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

_locales/en/messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@
390390
"backup_file_info": {
391391
"message": "Backup your data to a file."
392392
},
393+
"password_policy_default_hint": {
394+
"message": "Your password does not meet your organization's security requirements. Contact your administrator for more information."
395+
},
393396
"advisor": {
394397
"message": "Advisor"
395398
},

manifests/schema-chrome.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
"title": "Enforce autolock",
3636
"description": "If any value is set, then the user will not be able to change the autolock setting. Set to a number in minutes.",
3737
"type": "number"
38+
},
39+
"passwordPolicy": {
40+
"title": "Password policy",
41+
"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]+/).",
42+
"type": "string"
43+
},
44+
"passwordPolicyHint": {
45+
"title": "Password policy hint",
46+
"description": "Hint to show if the password doesn't meet the security requirements.",
47+
"type": "string"
3848
}
3949
}
4050
}

src/components/Popup/SetPasswordPage.vue

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ export default Vue.extend({
3535
enforcePassword: function () {
3636
return this.$store.state.menu.enforcePassword;
3737
},
38+
passwordPolicy: function () {
39+
try {
40+
return new RegExp(this.$store.state.menu.passwordPolicy);
41+
} catch {
42+
console.warn(
43+
"Invalid password policy. The password policy is not a valid regular expression.",
44+
this.$store.state.menu.passwordPolicy
45+
);
46+
return null;
47+
}
48+
},
49+
passwordPolicyHint: function () {
50+
return this.$store.state.menu.passwordPolicyHint;
51+
},
3852
},
3953
methods: {
4054
async removePassphrase() {
@@ -49,6 +63,13 @@ export default Vue.extend({
4963
return;
5064
}
5165
66+
if (this.passwordPolicy && !this.passwordPolicy.test(this.phrase)) {
67+
const hint =
68+
this.passwordPolicyHint || this.i18n.password_policy_default_hint;
69+
this.$store.commit("notification/alert", hint);
70+
return;
71+
}
72+
5273
if (this.phrase !== this.confirm) {
5374
this.$store.commit("notification/alert", this.i18n.phrase_not_match);
5475
return;

src/store/Menu.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export class Menu implements Module {
1818
enforceAutolock: await ManagedStorage.get("enforceAutolock"),
1919
storageArea: await ManagedStorage.get("storageArea"),
2020
feedbackURL: await ManagedStorage.get("feedbackURL"),
21+
passwordPolicy: await ManagedStorage.get("passwordPolicy"),
22+
passwordPolicyHint: await ManagedStorage.get("passwordPolicyHint"),
2123
},
2224
mutations: {
2325
setZoom: (state: MenuState, zoom: number) => {

0 commit comments

Comments
 (0)