Example #1
0
 function Login($username = '', $password = '', $autoLogin = 0)
 {
     $loginSql = "SELECT id,adminLevel,userName,email,userPwd,validated,avatarImg,avatarImg_s,signature FROM " . $this->tbUser . " WHERE 1=1";
     $loginSql .= strpos($username, '@') ? " AND email='{$username}'" : " AND userName='******'";
     $row = $this->db->FirstRow($loginSql);
     if ($row && $row['userPwd'] == OCEncrypt($password)) {
         if (MAIL_AUTH && $row['validated'] == 0) {
             $this->ToValidate($row['email']);
         } else {
             $this->db->Execute("DELETE FROM " . $this->tbSession . " WHERE expires<" . time());
             $ocKey = OCEncrypt($row['id'] . '-' . $row['userName'] . '-' . $row['userPwd']);
             if ($autoLogin == 1) {
                 $this->expiryTime = 360 * 86400;
             }
             OCSetCookie('ocKey', $ocKey, time() + $this->expiryTime);
             $token = OCEncrypt(substr($ocKey, 0, 5) . time());
             $data = serialize(array('userId' => $row['id'], 'adminLevel' => $row['adminLevel'], 'userName' => $row['userName'], 'avatarImg' => $row['avatarImg'], 'avatarImg_s' => $row['avatarImg_s'], 'signature' => $row['signature']));
             $sqlValue = array('userId' => $row['id'], 'ocKey' => $ocKey, 'token' => $token, 'ip' => IP(), 'data' => $data, 'expires' => time() + $this->expiryTime, 'updateTime' => time(), 'addTime' => time());
             $sessionExisted = $this->db->FirstValue("SELECT COUNT(*) FROM " . $this->tbSession . " WHERE ocKey='{$ocKey}'");
             if ($sessionExisted > 0) {
                 $this->db->AutoExecute($this->tbSession, $sqlValue, 'UPDATE', " ocKey='{$ocKey}'");
             } else {
                 $this->db->AutoExecute($this->tbSession, $sqlValue);
             }
             $this->db->Execute("UPDATE " . $this->tbUser . " SET loginTime='" . time() . "' where id={$row['id']}");
         }
         return true;
     } else {
         return false;
     }
 }
Example #2
0
 public static function login($me = array())
 {
     $me['IP'] = IP();
     $me['FIRST'] = $me['LAST'] = now();
     self::$me = $me;
     if (!self::$hash) {
         self::$hash = md5(microtime(true) . SECRET);
     }
     self::setCookie();
     $pipeline = R::pipeline()->DEL(self::$prefix . self::$hash)->MULTI();
     foreach (self::$me as $k => $v) {
         $pipeline->HSET(self::$prefix . self::$hash, $k, $v);
     }
     $pipeline->EXPIRE(self::$prefix . self::$hash, USER_SESSION_TIMEOUT);
     $pipeline->EXEC()->execute();
 }
Example #3
0
function the_user()
{
    if (isset($_COOKIE[User_LoginKey])) {
        $getcookie = myDecrypt($_COOKIE[User_LoginKey], UserLogin_CryptKey);
        //var_export($getcookie);
        //var_export($_COOKIE[User_LoginKey]);
        load_lib("user", "userinfo");
        $userinfo = new userinfo();
        //这儿必须要 对象化,不然unserialize,提示错误
        $userinfo = unserialize($getcookie);
        if ($userinfo && $userinfo->user_name != "" && $userinfo->user_loginIP == IP()) {
            //判断cookie的合法性
            return $userinfo;
        }
        return false;
    }
    return false;
}
Example #4
0
    $table = htmlentities(stripslashes($quefa[0]));
    $colum = htmlentities(stripslashes($quefa[1]));
    $query = query("SELECT {$colum} FROM {$table} WHERE id = '{$user_id}'");
    $query = num_rows($query);
    $ticket = Ticket();
    if ($query == 0) {
        query("UPDATE {$table} SET {$colum} = '{$ticket}' WHERE id = '{$user_id}'");
    } else {
        query("UPDATE {$table} SET {$colum} = '{$ticket}' WHERE id = '{$user_id}'");
        $ticketsql = query("SELECT {$colum} FROM {$table} WHERE id = '{$user_id}'");
        $ticketrow = fetch($ticketsql);
        $ticket = $ticketrow[$colum];
    }
} else {
    // Start the Querys
    $user_ip = IP();
    $user_id = htmlentities(stripslashes($_SESSION['id']));
    $query = query("SELECT auth_ticket FROM users WHERE id = '{$user_id}'");
    $query = num_rows($query);
    $ticket = Ticket();
    if ($query == 0) {
        query("UPDATE users SET auth_ticket = '{$ticket}' WHERE id = '{$user_id}'");
    } else {
        query("UPDATE users SET auth_ticket = '{$ticket}' WHERE id = '{$user_id}'");
        $ticketsql = query("SELECT auth_ticket FROM users WHERE id = '{$user_id}'");
        $ticketrow = fetch($ticketsql);
        $ticket = $ticketrow['auth_ticket'];
    }
}
/*
 * * Header of Client