Jump to content

error with login script;ysql_connect(): Access denied for user 'root'@'localhost


runnerjp

Recommended Posts

this is what is happening when i try and log in... for some reason it comes up with this error

 

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in /home/runnerse/public_html/website/login/include/mysql.inc.php on line 36

 

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in /home/runnerse/public_html/website/login/include/mysql.inc.php on line 36

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/runnerse/public_html/website/login/include/mysql.inc.php on line 76

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/runnerse/public_html/website/login/include/auth.inc.php on line 52

 

below i have added the files associated with it

 

 

config.php

<?PHP

        // Protect from direct access
        if(ereg('config.php', $HTTP_SERVER_VARS['REQUEST_URI'])) die('You are not allowed to access this page directly.');


    
    $db['server']          = 'localhost';  
      
  
    $db['user']            = 'runnerse';
    

    $db['pass']            = '';
    

    $db['name']            = 'runnerse_login';
    
  
    $db['table']           = 'users';



    $pg['name']            = 'RunnersElite';
    

    $pg['admin']           = 'admin';
    

    $pg['pass']            = '';
    

    $pg['email']           = '[email protected]';
    
    // Member's page (if more than one, the first they see)
    $pg['page']            = './members.php';
    
    // Login page
   
    $pg['login']           = './login.php';

    // Allow new signup's (true / false)  
    $pg['signup']          = true;
    
   
    $pg['weburl']          = 'http://runnerselite.com';
    

    $pg['siteurl']         = 'http://runnerselite/login/';
    
   
    
    e:

    // Enable security code on signup (true / false)
    $pg['code']            = true;
    
    // Security code length (max: 7)
    $pg['codeLen']         = 5;
    
    // Allow multiple admins (true / false)
    // If enabled, users set as admins will have full rights on admin.php
    $pg['addadmin']        = true;
    
    // Default level
    // Level (from 1 to 99) that is set to the news users when they signup
    $pg['userlevel']       = 1;
    
    // Minimum level required to be able to see the user list
    // (0 to disable it)
    $pg['userlist']			= 0;
    
    // Allow users to contact you and other users?
    // 0: No; 1: Only registered users; 2: All visitors
    $pg['usermail']        = 2;
    
    // No security codes for admins
    // If enabled, admins won't be asked for a security code anywhere
    $pg['adminCode']       = true;
    
    // User Profiles
    // 0: Disabled; 1: Only admin's can see them; 2: Only registered users can see them; 3: Enabled
    $pg['profiles']        = 2;
    
    // Set a minimum and maximum of characters when sending an email (10 and 1000, respectively)
    $pg['mailLength']      = true;
    
    // Encryptation Method
    // Available Options: 'sha1', 'md5'
    // Warning: Don't change this if you already installed the script, it would break all accounts!
    $pg['encrypt']         = 'md5';

// ****************************************************************
// DO NOT CHANGE!
    // Restore table name, if deleted
    if(empty($db['table'])) $db['table'] = 'plus_signup';

    // Decrease "security code length" if higher than 7
    if($pg['codeLen'] > 7) $pg['codeLen'] = 7;
    
    // Set the value of 'usermail' to 0 if it's incorrect
    if($pg['usermail'] < 0 || $pg['usermail'] > 2) $pg['usermail'] = 0;
// ****************************************************************

// ****************************************************************
// DO NOT CHANGE!
    // URL Management
    $GET = array();
    foreach($HTTP_GET_VARS as $name => $value) {
        $GET[$name] = htmlspecialchars(strip_tags($value));
    }
// ****************************************************************
?>

 

mysql.inc

 

<?PHP
// Data Access Layer Class
class dal {
var $host;
var $port;
var $user;
var $pass;
var $db;
var $tbl;

var $sql_error; // holds last mysql_error()
var $connection; // hold connection link

// Get database access information
function dal($host, $port, $user, $pass, $db, $tbl) {
	$this->host = $host;
	$this->port = $port;
	$this->user = $user;
	$this->pass = $pass;
	$this->db = $db;
	$this->tbl = $tbl;
}

// Connect To MySQL
function connect() {
	if($this->connection) {
		return 1;
	}

	if($this->port != "") {
		$host = $this->host.":".$this->port;
	} else {
		$host = $this->host;
	}

	if($this->connection=mysql_connect($host, $this->user, $this->pass)) {
		if($this->selectdb($this->db)) {
			return 1;
		} else {
			return 0;
		}
	} else {
		$this->sql_error = mysql_error();
		return 0;
	}
}

// Select MySQL Database
function selectdb($db) {
	if(mysql_select_db($db, $this->connection)) {
		return 1;
	} else {
		$this->sql_error = mysql_error();
		return 0;
	}
}

// For SQL querys that don't get any data
// (you will get the number of affected rows if it works, or -1 if it fails)
function sql($sql) {
	if(empty($connection)) $this->connect();

	if(mysql_query($sql, $this->connection)) {
		$affected_records = mysql_affected_rows();
		return $affected_records;
	} else {
		$this->sql_error = mysql_error();
		return -1;
	}
}

// For SQL queries you use to retrieve data (1 if it works, -1 if it fails)
function selectsql($sql) {
	if(empty($connection)) $this->connect();

	if($result = mysql_query($sql, $this->connection)) {
		return $result;
	} else {
		$this->sql_error = mysql_error();
		return -1;
	}
}

function freeresult($result) {
	if(mysql_free_result($result)) {
		return 1;
	} else {
		$this->sql_error = mysql_error();
		return 0;
	}
}

// String escape function
function clear($string) {
	return (get_magic_quotes_gpc()) ? $string : mysql_real_escape_string($string);
}

// Closes MySQL Connection
function close() {
	if(mysql_close($this->connection)) {
		return 1;
	} else {
		$this->sql_error = mysql_error();
		return 0;
	}
}
}

?>

 

 

auth.inc

 

<?PHP
// Members Handling Class
class auth {

// Linked to the $_db class and $pg configuration array
var $_db;
var $pg;

// Login information
var $username;
var $encrypted_password;

// Array holding all the user's data
var $userdata = array();

// Is the user logged in?
var $logged = false;
var $lastLogin;

// Constructor
function auth(&$_db, &$pg) {
	// Set a link the $_db class
	$this->_db = &$_db;
	$this->pg = &$pg;
}

// encrypt a string (password)
function encrypt($str) {
	if($pg['encrypt'] === 'md5') {
		return md5($str);
	} else {
		return sha1($str);
	}
}

// Check if a string (password) is encrypted
function isencrypted($str) {
	return (strlen($str) === 40) ? true : false;
}

// Check if a username exists and, if needed, get it's password
// (Parameters should already be cleared)
function isUser($username, $getPass = 'false') {
	$this->_db->connect();

	if(!$getPass) {
		// Check if the username exists and return bool.
		return ($_db->sql("SELECT COUNT(*) FROM `".$_db->tbl."` WHERE `username`='".$username."'") === 1) ? true : false;
	} else {
		// Check if the username exists and return its encrypted password or false.
		$query = $this->_db->selectsql("SELECT `password` FROM `".$this->_db->tbl."` WHERE `username`='".$username."'");
		if($row = mysql_fetch_array($query)) {
			$this->_db->freeresult($query);
			return $row['password'];
		} else {
			// Username doesn't exist
			return false;
		}
	}
}

// Check login information and proceed with login proccess if applicable
// (Parameters should already be cleared)
function login($username, $password) {
	// Check if the password is already encrypted; if not, do it.
	if(!$this->isencrypted($password)) $password = $this->encrypt($password);

	// Check if the username exists
	$getPass = $this->isUser($username, true);
	if(!$getPass) return -1;

	// Check if the password is correct
	if($getPass !== $password) return -2;

	// It seems everything is correct, log in
	$this->username = $username;
	$this->encrypted_password = $password;
	$this->logged = true;

	// Save current timestamp as `last_login`
	$this->_db->connect();
	$this->_db->sql("UPDATE `".$this->_db->tbl."` SET `last_login`='".time()."' WHERE `username`='".$username."' && `password`='".$password."'");
	$this->lastLogin = time();

	return true;
}

// Retrieve current user's data and save it in an array
function loadData() {
	if(!$this->logged) return false;
	$this->_db->connect();
	$query = $this->_db->selectsql("SELECT * FROM `".$this->_db->tbl."` WHERE `username`='".$this->username."' && `password`='".$this->encrypted_password."'");

	if($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
		$this->userdata = $row;
		return true;
	} else 
		return false;
}

// Returns an array with the current user's data; if needed, runs loadData() before
function getData($what='') {
	// Check if the user is logged in
	if(!$this->logged) return false;

	// If needed, run loadData()
	if(empty($this->userdata)) $this->loadData();

	// If everything worked fine, return the array
	if(empty($what)) {
		return (is_array($this->userdata)) ? $this->userdata : false;
	} else if(array_key_exists($what, $this->userdata)) {
		return $this->userdata[$what];
	} else {
		return false;
	}
}

// Retrieves and returns an array with the data of another user
function getDataById($id) {
	$this->_db->connect();
	$query = $this->_db->selectsql("SELECT * FROM `".$this->_db->tbl."` WHERE `id`='".$id."' LIMIT 1");

	if($row = mysql_fetch_array($query)) {
		$this->_db->freeresult($query);
		return $row;
	} else 
		return false;
}

// Returns the ID of a user from it's username
function getIdByUser($username) {
	$this->_db->connect();
	$query = $this->_db->selectsql("SELECT `id` FROM `".$this->_db->tbl."` WHERE `username`='".$username."'");

	return (($row = mysql_fetch_array($query)) && $this->_db->freeresult($query)) ? $row['id'] : false;
}

// Logout
function logout() {
	// Destroy variables
	$this->username = null;
	$this->encrypted_password = null;
	$this->userdata = null;

	// Kill Session
	session_destroy();

	return true;
}

// Check if it's the config-admin-user
function isRoot($username, $password) {
	if($this->pg['admin'] !== $username) return -1;
	if($this->pg['pass'] !== $password) return -2;
	return true;
}

// Check if it's a admin-user
function isAdmin($username='', $password='') {
	if(!$this->isencrypted($password)) $password = $this->encrypt($password);

	if(empty($username)) {
		$user = $this->getData();
	} else {
		$this->login($username, $password);
		$this->loadData();
	}

	return ($this->userdata['admin']) ? true : false;
}

// Check if a username has a valid format
function checkName($username) {
	if(empty($username)) return -1;
	if(strlen($username) < 3) return -2;
	if(strlen($username) > 15) return -3;
	return 1;
}

}

?>

 

even if i try and register a new user i get

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in /home/runnerse/public_html/website/login/include/mysql.inc.php on line 46

 

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in /home/runnerse/public_html/website/login/include/mysql.inc.php on line 46

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/runnerse/public_html/website/login/include/mysql.inc.php on line 86

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/runnerse/public_html/website/login/include/auth.inc.php on line 59

You have to write your full name.

 

 

 

so its not connecting to the db but i dont get why :S

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.