Created
August 6, 2013 09:42
-
-
Save yakirh/6163177 to your computer and use it in GitHub Desktop.
Testing random alphanumeric token exercise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| try | |
| { | |
| $length = 8; | |
| $start_time = microtime(TRUE); | |
| for ($i = 1; $i <= 10000; $i++) | |
| { | |
| $token = $this->rand_alphanumeric($length); | |
| if (strlen($token) !== $length) | |
| throw new Exception('Token "'.$token.'" length is invalid. token length is '.(strlen($token)).' instead of '.$length); | |
| if ( ! preg_match('#[0-9]#',$token)) | |
| throw new Exception('Token "'.$token.'" is invalid. token must contain at least 1 digit'); | |
| if ( ! preg_match('#[a-zA-Z]#',$token)) | |
| throw new Exception('Token "'.$token.'" is invalid. token must contain at least 1 letter'); | |
| } | |
| $execution_time = (float) number_format(microtime(TRUE)-$start_time, 5); | |
| die("Success! ~~ Execution Time: $execution_time seconds"); | |
| } | |
| catch (Exception $e) | |
| { | |
| die($e->getMessage()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace "$this->rand_alphanumeric(" with your function.