Advertisement
Guest User

Untitled

a guest
May 14th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.29 KB | None | 0 0
  1. class MySQLDB
  2. {
  3.    var $connection;         //The MySQL database connection
  4.    var $num_active_users;   //Number of active users viewing site
  5.    var $num_active_guests;  //Number of active guests viewing site
  6.    var $num_members;        //Number of signed-up users
  7.    /* Note: call getNumMembers() to access $num_members! */
  8.  
  9.    /* Class constructor */
  10.    function MySQLDB(){
  11.       /* Make connection to database */
  12.       $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
  13.       mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
  14.      
  15.       /**
  16.        * Only query database to find out number of members
  17.        * when getNumMembers() is called for the first time,
  18.        * until then, default value set.
  19.        */
  20.       $this->num_members = -1;
  21.      
  22.       if(TRACK_VISITORS){
  23.          /* Calculate number of users at site */
  24.          $this->calcNumActiveUsers();
  25.      
  26.          /* Calculate number of guests at site */
  27.          $this->calcNumActiveGuests();
  28.       }
  29.    }
  30.  
  31.    /**
  32.     * confirmUserPass - Checks whether or not the given
  33.     * username is in the database, if so it checks if the
  34.     * given password is the same password in the database
  35.     * for that user. If the user doesn't exist or if the
  36.    * passwords don't match up, it returns an error code
  37.     * (1 or 2). On success it returns 0.
  38.     */
  39.    function confirmUserPass($username, $password){
  40.       /* Add slashes if necessary (for query) */
  41.       if(!get_magic_quotes_gpc()) {
  42.           $username = addslashes($username);
  43.       }
  44.  
  45.       /* Verify that user is in database */
  46.       $q = "SELECT password FROM ".TBL_USERS." WHERE username = '$username'";
  47.       $result = mysql_query($q, $this->connection);
  48.       if(!$result || (mysql_numrows($result) < 1)){
  49.          return 1; //Indicates username failure
  50.       }
  51.  
  52.       /* Retrieve password from result, strip slashes */
  53.       $dbarray = mysql_fetch_array($result);
  54.       $dbarray['password'] = stripslashes($dbarray['password']);
  55.       $password = stripslashes($password);
  56.  
  57.       /* Validate that password is correct */
  58.       if($password == $dbarray['password']){
  59.          return 0; //Success! Username and password confirmed
  60.       }
  61.       else{
  62.          return 2; //Indicates password failure
  63.       }
  64.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement