@@ -153,13 +153,44 @@ public function check_security_permissions($permission) {
153153
154154 }
155155
156- public function get_random_password ($ length = 8 ) {
157- $ base64_alphabet ='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ ' ;
156+ public function get_random_password ($ minLength = 8 , $ special = false ) {
157+ $ minLength = $ minLength || 10 ;
158+ if ($ minLength < 8 ) $ minLength = 8 ;
159+ $ maxLength = $ minLength + 5 ;
160+ $ length = mt_rand ($ minLength , $ maxLength );
161+
162+ $ alphachars = "abcdefghijklmnopqrstuvwxyz " ;
163+ $ upperchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ " ;
164+ $ numchars = "1234567890 " ;
165+ $ specialchars = "!@#_ " ;
166+
167+ $ num_special = 0 ;
168+ if ($ special == true ) {
169+ $ num_special = intval (mt_rand (0 , round ($ length / 4 ))) + 1 ;
170+ }
171+ $ numericlen = mt_rand (1 , 2 );
172+ $ alphalen = $ length - $ num_special - $ numericlen ;
173+ $ upperlen = intval ($ alphalen / 2 );
174+ $ alphalen = $ alphalen - $ upperlen ;
158175 $ password = '' ;
159- for ($ n =0 ;$ n <$ length ;$ n ++) {
160- $ password .=$ base64_alphabet [mt_rand (0 , 63 )];
176+
177+ for ($ i = 0 ; $ i < $ alphalen ; $ i ++) {
178+ $ password .= substr ($ alphachars , mt_rand (0 , strlen ($ alphachars ) - 1 ), 1 );
179+ }
180+
181+ for ($ i = 0 ; $ i < $ upperlen ; $ i ++) {
182+ $ password .= substr ($ upperchars , mt_rand (0 , strlen ($ upperchars ) - 1 ), 1 );
183+ }
184+
185+ for ($ i = 0 ; $ i < $ num_special ; $ i ++) {
186+ $ password .= substr ($ specialchars , mt_rand (0 , strlen ($ specialchars ) - 1 ), 1 );
161187 }
162- return $ password ;
188+
189+ for ($ i = 0 ; $ i < $ numericlen ; $ i ++) {
190+ $ password .= substr ($ numchars , mt_rand (0 , strlen ($ numchars ) - 1 ), 1 );
191+ }
192+
193+ return str_shuffle ($ password );
163194 }
164195
165196 public function crypt_password ($ cleartext_password ) {
0 commit comments