Skip to content

Commit c7a456a

Browse files
committed
luci-mod-system: enforce password policy
Validation is performed if the password complies to password policy. Signed-off-by: Christian Korber <ckorber@tdt.de>
1 parent 7d9552c commit c7a456a

3 files changed

Lines changed: 55 additions & 2 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
'require baseclass';
4+
'require uci';
5+
6+
return baseclass.extend({
7+
checkLength(p, required) {
8+
let enough = p.length >= parseInt(required);
9+
10+
if (required && !enough)
11+
return false;
12+
13+
return true;
14+
},
15+
16+
checkDigits(p) {
17+
let m = p.match(/\d/);
18+
19+
return m ? true : false;
20+
},
21+
22+
checkUpperLower(p) {
23+
24+
return /[a-z]/.test(p) && /[A-Z]/.test(p);
25+
},
26+
27+
checkSpecialChars(p) {
28+
let m = p.match(/[^a-zA-Z0-9]/);
29+
30+
return m ? true : false;
31+
}
32+
});

modules/luci-mod-system/htdocs/luci-static/resources/view/system/password.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'require uci';
77
'require form';
88
'require rpc';
9+
'require tools.password as pwtool';
910

1011
var formData = {
1112
data: {
@@ -27,11 +28,18 @@ var callSetPassword = rpc.declare({
2728

2829
return view.extend({
2930
checkPassword: function(section_id, value) {
31+
const uuid = '51af4ae847774aac863d4c94a9ba6d58';
32+
3033
var strength = document.querySelector('.cbi-value-description'),
3134
strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g"),
3235
mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g"),
3336
enoughRegex = new RegExp("(?=.{6,}).*", "g");
3437

38+
const pw_length = uci.get('luci_plugins', uuid, 'pw_length');
39+
const pw_digits = uci.get('luci_plugins', uuid, 'digits');
40+
const pw_ul = uci.get('luci_plugins', uuid, 'uc_lc');
41+
const special = uci.get('luci_plugins', uuid, 'special_characters');
42+
3543
if (strength && value.length) {
3644
if (false == enoughRegex.test(value))
3745
strength.innerHTML = '%s: <span style="color:red">%s</span>'.format(_('Password strength'), _('More Characters'));
@@ -43,14 +51,27 @@ return view.extend({
4351
strength.innerHTML = '%s: <span style="color:red">%s</span>'.format(_('Password strength'), _('Weak'));
4452
}
4553

54+
if (pw_length && !pwtool.checkLength(value, pw_length))
55+
return _('Policy: min. length of %s characters').format(pw_length);
56+
57+
if (pw_digits && !pwtool.checkDigits(value))
58+
return _('Policy: contain digits');
59+
60+
if (pw_ul && !pwtool.checkUpperLower(value))
61+
return _('Policy: contain uppercase/lowercase');
62+
63+
if (special && !pwtool.checkSpecialChars(value))
64+
return _('Policy: contain special characters');
65+
4666
return true;
4767
},
4868

4969
load: function() {
5070
return Promise.all([
5171
L.resolveDefault(fs.stat('/usr/sbin/uhttpd'), null),
5272
fs.lines('/etc/passwd'),
53-
uci.load('rpcd')
73+
uci.load('rpcd'),
74+
uci.load('luci_plugins')
5475
]);
5576
},
5677

modules/luci-mod-system/root/usr/share/rpcd/acl.d/luci-mod-system.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"luci": [ "getLEDs", "getTimezones", "getUSBDevices", "getUnixtime" ],
1111
"rc": [ "list" ]
1212
},
13-
"uci": [ "luci", "system", "rpcd" ]
13+
"uci": [ "luci", "system", "rpcd", "luci_plugins" ]
1414
},
1515
"write": {
1616
"file": {

0 commit comments

Comments
 (0)