Mercurial > hg > fapweb
comparison msite.inc.php @ 65:72b22729ae7e
Add function for generating vote keys into site lib.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 05 Oct 2013 12:51:31 +0300 |
parents | 71256605546b |
children | 230aacc22cb4 |
comparison
equal
deleted
inserted
replaced
64:e1b673be98ec | 65:72b22729ae7e |
---|---|
464 } | 464 } |
465 } | 465 } |
466 } | 466 } |
467 | 467 |
468 | 468 |
469 function stGenerateUserKey($uid) | |
470 { | |
471 $keyChars = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789"; | |
472 | |
473 while (TRUE) | |
474 { | |
475 // Generate one keycode | |
476 $key = ""; | |
477 for ($n = 0; $n < stGetSetting("userKeyLength"); $n++) | |
478 $key .= $keyChars[rand() % strlen($keyChars)]; | |
479 | |
480 // Check if it already exists, to avoid duplicates | |
481 $sql = stPrepareSQL("SELECT * FROM attendees WHERE key=%s", $key); | |
482 if (($res = @$db->query($sql)) !== FALSE) | |
483 { | |
484 if ($res->fetchColumn() === FALSE) | |
485 { | |
486 // Nope, add into database | |
487 $sql = stPrepareSQL( | |
488 "UPDATE attendees SET key=%s,active=0 WHERE id=%d", | |
489 $key, $uid); | |
490 | |
491 if (($res = $db->query($sql)) === FALSE) | |
492 { | |
493 stLogSQLError($sql); | |
494 return FALSE; | |
495 } | |
496 | |
497 return TRUE; | |
498 } | |
499 } | |
500 else | |
501 { | |
502 stLogSQLError($sql); | |
503 return FALSE; | |
504 } | |
505 } | |
506 } | |
469 ?> | 507 ?> |