66'require uci' ;
77'require form' ;
88'require rpc' ;
9+ 'require tools.password as pwtool' ;
910
1011var formData = {
1112 data : {
@@ -27,11 +28,18 @@ var callSetPassword = rpc.declare({
2728
2829return 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
0 commit comments