Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Root Access

Status
Not open for further replies.

cyberfreek

IS-IT--Management
Jun 12, 2002
60
0
0
US
below is a problem I have had with access in mysql. Thank you in advance.


I re-installed MySQL and didnt give root any password. This is the stage I am at right now.

When I am in the MYSQL monitor what I do is :

mysql> use mysql

mysql> SELECT host, user, password FROM user;


the result is a table that gives

host user password

localhost root
%
localhost root
%


....so in my PHP code I keep it at

*******
PHP
******

<?

// login.php - performs validation
// authenticate using form variables
$status = authenticate($f_user, $f_pass);
// if user/pass combination is correct
if ($status == 1)
{
// initiate a session
session_start();

// register some session variables
session_register(&quot;SESSION&quot;);

// including the username
session_register(&quot;SESSION_UNAME&quot;);
$SESSION_UNAME = $f_user;

// redirect to protected page
header(&quot;Location: ../content/jobs/job1.php&quot;);
exit();
}

else
// user/pass check failed
{
// redirect to error page
header(&quot;Location: ../errors/loginError.php?e=$status&quot;);
exit();
}

// authenticate username/password against a database
// returns: 0 if username and password is incorrect
// 1 if username and password are correct
function authenticate($user, $pass)
{
// configuration variables
// normally these should be sourced from an external file
// for example: include(&quot;dbconfig.php&quot;);
// variables explicitly set here for illustrative purposes
$db_host = &quot;localhost&quot;;
$db_user = &quot;root&quot;;
$db_pass = &quot;&quot;;
$db_name = &quot;dgi&quot;;

// check login and password
// connect and execute query
$connection = mysql_connect($db_host, $db_user, $db_pass) or die
(&quot;Unable FIRST ERROR ON LOGIN to connect to the Database!&quot;);
$query = &quot;SELECT id FROM resumes WHERE username = '$user' AND
password = PASSWORD('$pass')&quot;;
mysql_select_db($db_name);
$result = mysql_query($query, $connection) or die (&quot;Error SECOND
ERROR ON
LOGIN in
query: $query. &quot; . mysql_error());

// if row exists -> user/pass combination is correct

if (mysql_num_rows($result) == 1)
{
return 1;
}
// user/pass combination is wrong
else
{
return 0;
}
}

?>


****
MySQL
*****

I have a DB names dgi with only 1 table called resumes with 3 records

id INT,
username varChar(30),
password varChar(30)


I then inserted 1 person

INSERT INTO resumes VALUES (1, 'trevor' , 'niblock' );


and when I look at those they are all fine in the DB.

What I am trying to say is that I have total control in MySQL monitor
and I dont see any mistake at loginError.php

*******
login.php
*********

<html>
<head>
<title></title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html;
charset=iso-8859-1&quot;>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<?
echo &quot;Error Page if you user/password comboo failed at login.php&quot; ;
?>

</body></html>


SO I THINK ITS OBIVOUSLY TO DO WITH THE SESSION CONTROL RETURNING
A 0 AS IT DOESNT THINK THAT F_USER & F_PASS EXSIT WHEN THEY DDO
EXIST AND CORRESPOND TO THE DB.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top