Mercurial > hg > fapweb
changeset 69:30a4420e85ab
stGenerateUserKey() simply returns a generated key now (string) or FALSE if
there was a fatal error.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 11 Oct 2013 09:31:25 +0300 |
parents | 3ae137411706 |
children | d31fc2c53b2b |
files | msite.inc.php |
diffstat | 1 files changed, 8 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/msite.inc.php Fri Oct 11 09:29:44 2013 +0300 +++ b/msite.inc.php Fri Oct 11 09:31:25 2013 +0300 @@ -466,35 +466,29 @@ } -function stGenerateUserKey($uid) +function stGenerateUserKey() { + global $db; $keyChars = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789"; while (TRUE) { - // Generate one keycode + // Generate one randomized keycode $key = ""; for ($n = 0; $n < stGetSetting("userKeyLength"); $n++) $key .= $keyChars[rand() % strlen($keyChars)]; // Check if it already exists, to avoid duplicates + // We need custom query code here, because stFetchSQLColumn() + // won't work due to it returning FALSE in error cases. $sql = stPrepareSQL("SELECT * FROM attendees WHERE key=%s", $key); if (($res = @$db->query($sql)) !== FALSE) { + // Did we get results? if ($res->fetchColumn() === FALSE) { - // Nope, add into database - $sql = stPrepareSQL( - "UPDATE attendees SET key=%s,active=0 WHERE id=%d", - $key, $uid); - - if (($res = $db->query($sql)) === FALSE) - { - stLogSQLError($sql); - return FALSE; - } - - return TRUE; + // Nope, return key + return $key; } } else