Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MySQLDB
- {
- var $connection; //The MySQL database connection
- var $num_active_users; //Number of active users viewing site
- var $num_active_guests; //Number of active guests viewing site
- var $num_members; //Number of signed-up users
- /* Note: call getNumMembers() to access $num_members! */
- /* Class constructor */
- function MySQLDB(){
- /* Make connection to database */
- $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
- mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
- /**
- * Only query database to find out number of members
- * when getNumMembers() is called for the first time,
- * until then, default value set.
- */
- $this->num_members = -1;
- if(TRACK_VISITORS){
- /* Calculate number of users at site */
- $this->calcNumActiveUsers();
- /* Calculate number of guests at site */
- $this->calcNumActiveGuests();
- }
- }
- /**
- * confirmUserPass - Checks whether or not the given
- * username is in the database, if so it checks if the
- * given password is the same password in the database
- * for that user. If the user doesn't exist or if the
- * passwords don't match up, it returns an error code
- * (1 or 2). On success it returns 0.
- */
- function confirmUserPass($username, $password){
- /* Add slashes if necessary (for query) */
- if(!get_magic_quotes_gpc()) {
- $username = addslashes($username);
- }
- /* Verify that user is in database */
- $q = "SELECT password FROM ".TBL_USERS." WHERE username = '$username'";
- $result = mysql_query($q, $this->connection);
- if(!$result || (mysql_numrows($result) < 1)){
- return 1; //Indicates username failure
- }
- /* Retrieve password from result, strip slashes */
- $dbarray = mysql_fetch_array($result);
- $dbarray['password'] = stripslashes($dbarray['password']);
- $password = stripslashes($password);
- /* Validate that password is correct */
- if($password == $dbarray['password']){
- return 0; //Success! Username and password confirmed
- }
- else{
- return 2; //Indicates password failure
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement