@@ -582,11 +582,7 @@ public static function randomDigit(int $digit): string
582582 {
583583 $ resultStr = '' ;
584584 for ($ i = 0 ; $ i < $ digit ; $ i ++) {
585- try {
586- $ code = random_int (0 , 9 );
587- } catch (Exception $ ex ) {
588- $ code = rand (0 , 10 );
589- }
585+ $ code = random_int (0 , 9 );
590586 $ resultStr .= $ code ;
591587 }
592588 return $ resultStr ;
@@ -600,11 +596,7 @@ public static function randomString(int $digit): string
600596 {
601597 $ resultStr = '' ;
602598 for ($ i = 0 ; $ i < $ digit ; $ i ++) {
603- try {
604- $ code = random_int (33 , 126 );
605- } catch (Exception $ ex ) {
606- $ code = rand (33 , 126 );
607- }
599+ $ code = random_int (33 , 126 );
608600 $ resultStr .= chr ($ code );
609601 }
610602 return $ resultStr ;
@@ -620,11 +612,7 @@ public static function challengeString(int $digit): string
620612 $ len = strlen ($ chars );
621613 $ resultStr = '' ;
622614 for ($ i = 0 ; $ i < $ digit ; $ i ++) {
623- try {
624- $ code = random_int (0 , $ len - 1 );
625- } catch (Exception $ ex ) {
626- $ code = rand (0 , $ len - 1 );
627- }
615+ $ code = random_int (0 , $ len - 1 );
628616 $ resultStr .= $ chars [$ code ];
629617 }
630618 return $ resultStr ;
@@ -650,7 +638,7 @@ public static function generateChallenge(): string
650638 {
651639 $ str = '' ;
652640 for ($ i = 0 ; $ i < 24 ; $ i ++) {
653- $ n = rand (1 , 255 );
641+ $ n = random_int (1 , 255 );
654642 $ str .= ($ n < 16 ? '0 ' : '' ) . dechex ($ n );
655643 }
656644 return $ str ;
@@ -663,7 +651,7 @@ public static function generateSalt(): string
663651 {
664652 $ str = '' ;
665653 for ($ i = 0 ; $ i < 4 ; $ i ++) {
666- $ n = rand (33 , 126 ); // They should be an ASCII character for JS SHA1 lib.
654+ $ n = random_int (33 , 126 ); // They should be an ASCII character for JS SHA1 lib.
667655 $ str .= chr ($ n );
668656 }
669657 return $ str ;
@@ -680,10 +668,10 @@ public static function generatePassword(int $digit): string
680668 $ seedPunctuation = "#$%& " ;
681669 $ str = '' ;
682670 for ($ i = 0 ; $ i < $ digit - 1 ; $ i ++) {
683- $ n = rand (0 , strlen ($ seed ) - 1 );
671+ $ n = random_int (0 , strlen ($ seed ) - 1 );
684672 $ str .= substr ($ seed , $ n , 1 );
685673 }
686- $ n = rand (0 , strlen ($ seedPunctuation ) - 1 );
674+ $ n = random_int (0 , strlen ($ seedPunctuation ) - 1 );
687675 $ str .= substr ($ seedPunctuation , $ n , 1 );
688676 return $ str ;
689677 }
@@ -720,7 +708,7 @@ public static function generateCredentialWithRandomPW(int $digit, string $passwo
720708 {
721709 $ password = '' ;
722710 for ($ i = 0 ; $ i < $ digit ; $ i ++) {
723- $ password .= chr (rand (32 , 127 ));
711+ $ password .= chr (random_int (32 , 127 ));
724712 }
725713 return IMUtil::convertHashedPassword ($ password , $ passwordHash , $ alwaysGenSHA2 );
726714 }
@@ -731,17 +719,9 @@ public static function generateCredentialWithRandomPW(int $digit, string $passwo
731719 public static function generateRandomPW (): string
732720 {
733721 $ str = '' ;
734- try {
735- $ limit = random_int (15 , 20 );
736- } catch (Exception $ ex ) {
737- $ limit = rand (15 , 20 );
738- }
722+ $ limit = random_int (15 , 20 );
739723 for ($ i = 0 ; $ i < $ limit ; $ i ++) {
740- try {
741- $ n = random_int (33 , 126 ); // They should be an ASCII character for JS SHA1 lib.
742- } catch (Exception $ ex ) {
743- $ n = rand (33 , 126 ); // They should be an ASCII character for JS SHA1 lib.
744- }
724+ $ n = random_int (33 , 126 ); // They should be an ASCII character for JS SHA1 lib.
745725 $ str .= chr ($ n );
746726 }
747727 return $ str ;
0 commit comments