@@ -174,13 +174,44 @@ public function check_security_permissions($permission) {
174174
175175 }
176176
177- public function get_random_password ($ length = 8 ) {
178- $ base64_alphabet ='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ ' ;
177+ public function get_random_password ($ minLength = 8 , $ special = false ) {
178+ $ minLength = $ minLength || 10 ;
179+ if ($ minLength < 8 ) $ minLength = 8 ;
180+ $ maxLength = $ minLength + 5 ;
181+ $ length = mt_rand ($ minLength , $ maxLength );
182+
183+ $ alphachars = "abcdefghijklmnopqrstuvwxyz " ;
184+ $ upperchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ " ;
185+ $ numchars = "1234567890 " ;
186+ $ specialchars = "!@#_ " ;
187+
188+ $ num_special = 0 ;
189+ if ($ special == true ) {
190+ $ num_special = intval (mt_rand (0 , round ($ length / 4 ))) + 1 ;
191+ }
192+ $ numericlen = mt_rand (1 , 2 );
193+ $ alphalen = $ length - $ num_special - $ numericlen ;
194+ $ upperlen = intval ($ alphalen / 2 );
195+ $ alphalen = $ alphalen - $ upperlen ;
179196 $ password = '' ;
180- for ($ n =0 ;$ n <$ length ;$ n ++) {
181- $ password .=$ base64_alphabet [mt_rand (0 , 63 )];
197+
198+ for ($ i = 0 ; $ i < $ alphalen ; $ i ++) {
199+ $ password .= substr ($ alphachars , mt_rand (0 , strlen ($ alphachars ) - 1 ), 1 );
200+ }
201+
202+ for ($ i = 0 ; $ i < $ upperlen ; $ i ++) {
203+ $ password .= substr ($ upperchars , mt_rand (0 , strlen ($ upperchars ) - 1 ), 1 );
204+ }
205+
206+ for ($ i = 0 ; $ i < $ num_special ; $ i ++) {
207+ $ password .= substr ($ specialchars , mt_rand (0 , strlen ($ specialchars ) - 1 ), 1 );
182208 }
183- return $ password ;
209+
210+ for ($ i = 0 ; $ i < $ numericlen ; $ i ++) {
211+ $ password .= substr ($ numchars , mt_rand (0 , strlen ($ numchars ) - 1 ), 1 );
212+ }
213+
214+ return str_shuffle ($ password );
184215 }
185216
186217 public function crypt_password ($ cleartext_password ) {
0 commit comments