File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 77 class User {
88 private static function generateTokenCode () {
99 $ digits = 6 ;
10+
11+ self ::cleanupTokens ();
12+ $ existingTokens = self ::getExistingVerifyTokens ();
13+
14+ while (in_array ($ code , $ existingTokens )) { // make sure we have no collissions;
15+ $ code = random_int (0 ,1000000 );
16+ $ code = str_pad ($ code , $ digits , '0 ' , STR_PAD_LEFT );
17+ }
18+
1019 $ code = random_int (0 ,1000000 );
1120 $ code = str_pad ($ code , $ digits , '0 ' , STR_PAD_LEFT );
1221 return $ code ;
@@ -331,4 +340,14 @@ public static function cleanupTokens() {
331340 ':now ' => $ now ->getTimestamp ()
332341 ]);
333342 }
343+
344+ public static getExistingVerifyTokens () {
345+ Db::connect();
346+ $ query = Db::$ pdo ->prepare (
347+ 'SELECT code FROM verify '
348+ );
349+ $ existingTokens = $ query ->execute ();
350+ return $ existingTokens ;
351+ }
352+
334353 }
You can’t perform that action at this time.
0 commit comments