15 var callSetPassword
= rpc
.declare({
17 method
: 'setPassword',
18 params
: [ 'username', 'password' ],
19 expect
: { result
: false }
23 checkPassword: function(section_id
, value
) {
24 var strength
= document
.querySelector('.cbi-value-description'),
25 strongRegex
= new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g"),
26 mediumRegex
= new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g"),
27 enoughRegex
= new RegExp("(?=.{6,}).*", "g");
29 if (strength
&& value
.length
) {
30 if (false == enoughRegex
.test(value
))
31 strength
.innerHTML
= '%s: <span style="color:red">%s</span>'.format(_('Password strength'), _('More Characters'));
32 else if (strongRegex
.test(value
))
33 strength
.innerHTML
= '%s: <span style="color:green">%s</span>'.format(_('Password strength'), _('Strong'));
34 else if (mediumRegex
.test(value
))
35 strength
.innerHTML
= '%s: <span style="color:orange">%s</span>'.format(_('Password strength'), _('Medium'));
37 strength
.innerHTML
= '%s: <span style="color:red">%s</span>'.format(_('Password strength'), _('Weak'));
46 m
= new form
.JSONMap(formData
, _('Router Password'), _('Changes the administrator password for accessing the device'));
47 s
= m
.section(form
.NamedSection
, 'password', 'password');
49 o
= s
.option(form
.Value
, 'pw1', _('Password'));
51 o
.validate
= this.checkPassword
;
53 o
= s
.option(form
.Value
, 'pw2', _('Confirmation'), ' ');
55 o
.renderWidget = function(/* ... */) {
56 var node
= form
.Value
.prototype.renderWidget
.apply(this, arguments
);
58 node
.childNodes
[1].addEventListener('keydown', function(ev
) {
59 if (ev
.keyCode
== 13 && !ev
.currentTarget
.classList
.contains('cbi-input-invalid'))
60 document
.querySelector('.cbi-button-save').click();
69 handleSave: function() {
70 var map
= document
.querySelector('.cbi-map');
72 return dom
.callClassMethod(map
, 'save').then(function() {
73 if (formData
.password
.pw1
== null || formData
.password
.pw1
.length
== 0)
76 if (formData
.password
.pw1
!= formData
.password
.pw2
) {
77 ui
.addNotification(null, E('p', _('Given password confirmation did not match, password not changed!')), 'danger');
81 return callSetPassword('root', formData
.password
.pw1
).then(function(success
) {
83 ui
.addNotification(null, E('p', _('The system password has been successfully changed.')), 'info');
85 ui
.addNotification(null, E('p', _('Failed to change the system password.')), 'danger');
87 formData
.password
.pw1
= null;
88 formData
.password
.pw2
= null;
90 dom
.callClassMethod(map
, 'render');
95 handleSaveApply
: null,