Jump to content


Photo

Questions about MySQL


  • Please log in to reply
11 replies to this topic

#1 Fixxer

Fixxer
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 09 July 2006 - 12:28 PM

If I store the information using the MD5 function, how do I use php to convert it back to normal when I want to check a login? I used myphpadmin to convert it to MD5.

Also, what would I put for local host, my domain name?

#2 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 09 July 2006 - 12:48 PM

This is the whole point of MD5 , that you cannot reverse engineer it.

What you do is you store the MD5 informtion somewhere.

Then, when the user enters their login, you MD5 it and check if it is equal to the previous one.

So, if there is a field called PASSWORD in your table, you could do this to check it against what someone entered in a form:
$pass = $_POST['pass'];
$md5Pass = md5($pass);
$sql = "SELECT * FROM table WHERE PASSWORD='$md5Pass' ";
$result = mysql_query($sql);
I left some things out like DB connection etc. but it should get your started.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 09 July 2006 - 12:55 PM

as far as your 2nd question: in most cases, your local host can simply be "localhost" if that doesn't work, then yes, you will have to put your database server.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 Fixxer

Fixxer
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 09 July 2006 - 01:12 PM

Ok am trying this code, but so far no login!

<?php

$dbHost = "localhost";
$dbUsername = "edited";
$dbPassword = "edited";
$dbName = "Xiemsoft_Site";
#$username = $_POST['user'];
#$password = $_POST['pass'];
$username = "testname";
$password = "testpass";
$md5Password = MD5($password);

$link = mysql_connect($dbHost,$dbUsername,$dbPassword);

mysql_select_db($dbName,$link);

$SQL = "SELECT username FROM webhosting WHERE username = \"$username\" AND password = \"$md5Password\"";

$result = mysql_query($SQL,$link);

if(mysql_num_rows($result) == 0)
{
  $message = "Invalid Login.";
}
else
{
  $message = "Logged In!";
}

?>


#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 09 July 2006 - 01:17 PM


Your problem might be that MySQL wants string surrounded by single quotes, not double quotes. Make sure you have an "or die" clause on all your mysql functions that might cause an error.

<?php
$db_host = "host";
$db_user = "name";
$db_pass = "pass";
$db_name = "name";
$pass = "name"
$username = "pass"
$link = mysql_connect($db_host, $db_user, $db_pass) or die("Couldn't connect to the database<br>" . mysql_error());
mysql_select_db($db_name, $link) or die("Couldn't select database<br>" . mysql_error());
$query = "SELECT username FROM webhosting WHERE username = '$username' AND password = '$pass' ";
$result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());
if(mysql_num_rows($result) == 0)
{
  $message = "LOSER";
}
else // the number of rows is either going to be zero or one, so you only need the else here
{
  $message = "WINNER";
}
?>
<html>
<head>
<title>TEST</title>
</head>
<body>
TESTING 123...
<?php echo $message; ?>
</body>
</html>
Whenever you're debugging, make sure the error reporting is set to the maximum by putting this at the top of your script:
<?php
// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting(E_ALL);
?>

Ken

#6 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 09 July 2006 - 01:23 PM

You're right, at the top of all your files you should put this:
error_reporting(E_ALL);
Because PHP should have thrown an error on the SQL line because of your use of double quotes inside a double quotes string.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#7 Fixxer

Fixxer
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 09 July 2006 - 01:26 PM

Ahh thanks, it appears that I cannot connect :x

Couldn't connect to the database
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

#8 Fixxer

Fixxer
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 09 July 2006 - 07:02 PM

Does anyone know what that means?

#9 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 09 July 2006 - 07:04 PM

It most likely means that your mysql database is not up.

Ken

#10 Fixxer

Fixxer
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 09 July 2006 - 09:16 PM

It is, i created it using phpmyadmin.

#11 Fixxer

Fixxer
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 12 July 2006 - 03:39 PM

Bump

#12 Fixxer

Fixxer
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 17 July 2006 - 08:24 PM

bump




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users