Jump to content

Questions about MySQL


Fixxer

Recommended Posts

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?
Link to comment
Share on other sites

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:
[code]
$pass = $_POST['pass'];
$md5Pass = md5($pass);
$sql = "SELECT * FROM table WHERE PASSWORD='$md5Pass' ";
$result = mysql_query($sql);
[/code]
I left some things out like DB connection etc. but it should get your started.
Link to comment
Share on other sites

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

[code]
<?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!";
}

?>
[/code]
Link to comment
Share on other sites


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.

[code]<?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>[/code]
Whenever you're debugging, make sure the error reporting is set to the maximum by putting this at the top of your script:
[code]<?php
// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting(E_ALL);
?>[/code]

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.