- $ERROR = CODE_EXTENSION_PROBLEM;
-} elseif (isset($_POST['ok'])) {
- // Add last_login if available
- $LAST = "";
- if (GET_EXT_VERSION("sql_patches") >= "0.2.8") {
- $LAST = ", last_login";
- } // END - if
-
- // Check login data
- $password = "";
- if ($probe_nickname === true) {
- // Nickname entered
- $result = SQL_QUERY_ESC("SELECT userid, password, last_online".$LAST." FROM "._MYSQL_PREFIX."_user_data WHERE nickname='%s' AND status='CONFIRMED' LIMIT 1",
- array($uid), __FILE__, __LINE__);
- list($uid2, $password, $online, $login) = SQL_FETCHROW($result);
- if (!empty($uid2)) $uid = bigintval($uid2);
- } else {
- // Direct userid entered
- $result = SQL_QUERY_ESC("SELECT userid, password, last_online".$LAST." FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s AND status='CONFIRMED' LIMIT 1",
- array($uid, $hash), __FILE__, __LINE__);
- list($dmy, $password, $online, $login) = SQL_FETCHROW($result);
- }
-
- // Is there an entry?
- if (SQL_NUMROWS($result) == 1) {
- // By default the hash is empty
- $hash = "";
-
- // Check for old MD5 passwords
- if ((strlen($password) == 32) && (md5($_POST['password']) == $password)) {
- // Just set the hash to the password from DB... :)
- $hash = $password;
- } else {
- // Encrypt hash for comparsion
- $hash = generateHash($_POST['password'], substr($password, 0, -40));
- }
-
- if ($hash == $password) {
- // New hashed password found so let's generate a new one
- $hash = generateHash($_POST['password']);
-
- // ... and update database
- $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET password='%s' WHERE userid=%s AND status='CONFIRMED' LIMIT 1",
- array($hash, $uid), __FILE__, __LINE__);
-
- // No login bonus by default
- $BONUS = false;
-
- // Probe for last online timemark
- $probe = time() - $online;
- if (!empty($login)) $probe = time() - $login;
- if ((GET_EXT_VERSION("bonus") >= "0.2.2") && ($probe >= $_CONFIG['login_timeout'])) {
- // Add login bonus to user's account
- $ADD = ", login_bonus=login_bonus+'".$_CONFIG['login_bonus']."'";
- $BONUS = true;
-
- // Subtract login bonus from userid's account or jackpot
- if ((GET_EXT_VERSION("bonus") >= "0.3.5") && ($_CONFIG['bonus_mode'] != "ADD")) BONUS_POINTS_HANDLER('login_bonus');
- } // END - if
-
-
- // Secure lifetime from input form
- $l = bigintval($_POST['lifetime']);
- $life = "-1";
- if ($l > 0) {
- // Calculate lifetime of cookies
- $life = time() + $l;
-
- // Calculate new hash with the secret key and master salt together
- $hash = generatePassString($hash);
-
- // Update cookies
- $login = (set_session("userid" , $uid , $life, COOKIE_PATH)
- && set_session("u_hash" , $hash, $life, COOKIE_PATH)
- && set_session("lifetime", $l , $life, COOKIE_PATH));
-
- // Update global array
- $GLOBALS['userid'] = $uid;
- } else {
- // Check for login data
- $login = IS_MEMBER();
- }
-
- if ($login) {
- // Update database records
- $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET total_logins=total_logins+1".$ADD." WHERE userid=%s LIMIT 1",
- array($uid), __FILE__, __LINE__);
- if (SQL_AFFECTEDROWS() == 1) {
- // Procedure to checking for login data
- if (($BONUS) && (EXT_IS_ACTIVE("bonus"))) {
- // Bonus added (just displaying!)
- $URL = URL."/modules.php?module=chk_login&mode=bonus";
- } else {
- // Bonus not added
- $URL = URL."/modules.php?module=chk_login&mode=login";
- }
- } else {
- // Cannot update counter!
- $URL = URL."/modules.php?module=index&what=login&login=".CODE_CNTR_FAILED;
- }
- } else {
- // Cookies not setable!
- $URL = URL."/modules.php?module=index&what=login&login=".CODE_NO_COOKIES;
- }
- } else {
- // Update failture counter
- SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET login_failtures=login_failtures+1,last_failture=NOW() WHERE userid=%s LIMIT 1",
- array($uid), __FILE__, __LINE__);
-
- // Wrong password!
- $ERROR = CODE_WRONG_PASS;
- }