18.05.2010, 16:06
Hello, I am working on my webpage for my server and use a lot of Mysql. One of feature is login on webpage using your in-game username and password. Passwords are hashed in pawno using md5, and I guess it should be also in my php login sctipt. But how? I tried like this but it is still returning me Invalid password. Here is my PHP password:
Anyone know how to fix log in and hashing passwords in PHP?
Thanks!
Код:
<?php
/*session_start();*/
$username = $_POST['username'];
$password = $_POST['password'];
if($username&&$password)
{
$connect = mysql_connect("non", "non", "non") or die ("Couldn't connect!");
$selectdb = mysql_select_db("non") or die ("Couldn't select database!");
$query = mysql_query("SELECT * FROM users WHERE Username='$username'");
$numrows = mysql_num_rows($query);
if($numrows!=0)
{
//check for login
while($row = mysql_fetch_assoc($query))
{
$dbusername = $row['Username'];
$dbpassword = $row['Password'];
}
//check if the match!
if($username==$dbusername&&md5($password)==$dbpassword)
{
$_SESSION['username']=$username;
echo $row['Username'];
$query1 = mysql_query("SELECT * FROM users WHERE Username='$username'");
$assoc = mysql_fetch_assoc($query1);
echo "Welcome <b>".$assoc['Username']."</b>";
echo "<p>";
echo "<br>";
echo "You currently have <b>".$assoc['Kills']."</b> kills and <b>".$assoc['Deaths']."</b> deaths.";
echo "<br>";
echo "<p>";
if($assoc['Admin Level'] == 1)
{
echo "You are <b>Moderator!</b>";
}
if($assoc['Admin Level'] == 2)
{
echo "You are <b>Administrator!</b>";
}
if($assoc['Admin Level'] == 3)
{
echo "You are <b>Server Owner!</b>";
}
if($assoc['VIP'] == 1)
{
echo "<br>";
echo "<p>";
echo "You are <b>VIP Member!</b>";
}
echo "<br>";
echo "<p>";
echo "<a href='logout.php'>Logout!</a>";
if($assoc['Admin Level'] == 0)
{
echo "<br>";
echo "<p>";
echo "<a href='ModeratorApplications.php'>Moderator Applications</a>";
}
if($assoc['Admin Level'] == 3)
{
echo "<br>";
echo "<a href='modadmin.php'>Look For New Moderator Applications!</a>";
}
if($assoc['Admin Level'] == 2)
{
echo "You are <b>Server Owner!</b>";
echo "<br>";
echo "<a href='modadmin.php'>Look For New Moderator Applications!</a>";
}
}
else
echo "Incorrect password!";
}
else
die("That user doesn't exist!");
}
else
die("Please enter and username and password!");
?>
Thanks!



