Jump to content

[SOLVED] Login in issue!


Foser

Recommended Posts

Ok for some reason I have a issue login in.

 

- I have check the for the registration to also be MD5-SHA1-MD5-MD5.

 

Here is my code:

 

<?php
require("config.php");

$user = mysql_real_escape_string($_POST['user']);
$pw = md5(sha1(md5(md5($_POST['pw']))));

mysql_fetch_assoc(mysql_query("SELECT * FROM user_info WHERE username = '$user' and password = '$pw'")) or die(mysql_error());

if ($pw == $user_info['password'] && $user == $user_info['username']){
mysql_fetch_assoc(mysql_query("SELECT rights FROM user_info WHERE username = '$user'")) or die(mysql_error()); 
echo "You are now logged in as a $user_info[rights].";
echo "<br>Welcome!"; }
else {
echo "You have typed in an incorrect password or/and username. Please try again."; }

?>                                 

 

When I type in the false data nothing is executed leads me to a blank page. When I put in the correct data it will show me my else statement: You have typed in an incorrect password or/and username. Please try again.

 

thank you a lot!

 

Link to comment
Share on other sites

<?php

require("config.php");

$user = mysql_real_escape_string($_POST['user']);
$pw = md5(sha1(md5(md5($_POST['pw']))));

// if query succeeds, save the results in the var $result
if ($result = mysql_query("SELECT * FROM user_info WHERE username = '$user' and password = '$pw'")) {
  // check a user was found.
  if (mysql_num_rows($result)) {
    // fetch data into $row
    $row = mysql_fetch_assoc($result); 
    echo "You are now logged in as a {$row['rights']}.";
    echo "<br>Welcome!";
  } else {
    echo "You have typed in an incorrect password or/and username. Please try again."; }
  }
} else {
  echo mysql_error();
}
?>

Link to comment
Share on other sites

Alright I have edited my code :

 

<?php
require("config.php");

$user = mysql_real_escape_string($_POST['user']);
$pw = md5(sha1(md5(md5($_POST['pw']))));

if ($result = ("SELECT * FROM user_info WHERE username = '$user' and password = '$pw'")){
if (mysql_num_rows($result)){
$row = mysql_fetch_assoc($result);
echo "You are now logged in as a $user_info[rights].";
echo "<br>Welcome!";}}

else {
echo "You have typed in an incorrect password or/and username. Please try again."; }

?>                                 

 

 

But now I get a error : (Line 8 is the $row =...)

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\WAMP\www\Tutorials\PHP_MYSQL\Simple_MySQL\Login\login.php on line 8

 

thanks

 

Link to comment
Share on other sites

Now your not executing the query. This line....

 

if ($result = ("SELECT * FROM user_info WHERE username = '$user' and password = '$pw'")){

 

Needs to be....

 

if ($result = mysql_query("SELECT * FROM user_info WHERE username = '$user' and password = '$pw'")) {

Link to comment
Share on other sites

<?php
require("config.php");

$user = mysql_real_escape_string($_POST['user']);
$pw = md5(sha1(md5(md5($_POST['pw']))));

if ($result = mysql_query("SELECT * FROM user_info WHERE username = '$user' and password = '$pw'")){
if (mysql_num_rows($result)or die(mysql_error())) {
$row = mysql_fetch_assoc($result);
echo "You are now logged in as a {$row['rights']}.";
echo "<br>Welcome!";}

else {
echo "You have typed in an incorrect password or/and username. Please try again."; }}

else {
echo mysql_error();}

?>                                 

 

 

Link to comment
Share on other sites

Pull the $row['rights'] out and save it in it's own variable. I've had many, many problems trying to use an array variable like that inside quotes.

<?php
require("config.php");

$user = mysql_real_escape_string($_POST['user']);
$pw = md5(sha1(md5(md5($_POST['pw']))));

if ($result = mysql_query("SELECT * FROM user_info WHERE username = '$user' and password = '$pw'")) {
if (mysql_num_rows($result)or die(mysql_error())) {
	$row = mysql_fetch_assoc($result);
	$rights = $row["rights"];
	echo "You are now logged in as a {$rights}.";
	echo "<br>Welcome!";
} else {
	echo "You have typed in an incorrect password or/and username. Please try again.";
}
} else {
echo mysql_error();
}
?>

 

I have another question though. Why are you hashing the password 4 times? Are you doing secret work for the FBI or something? ;)

Link to comment
Share on other sites

That was my first question. My second issue, is my else statement does not execute.

Therefore when I write the incorrect data it shows a blank page. instead of wrong password or username.

Could anyone help?

 

 

The reason I am hashing more than once is it is more secure than only a simple one time sha1 or one time MD5.They are reasonably easy to decrypt.

Link to comment
Share on other sites

Because of it being a new page I'll repost the script.

 

<?php
require("config.php");

$user = mysql_real_escape_string($_POST['user']);
$pw = md5(sha1(md5(md5($_POST['pw']))));

if ($result = mysql_query("SELECT * FROM user_info WHERE username = '$user' and password = '$pw'")){
if (mysql_num_rows($result)or die(mysql_error())) {
$row = mysql_fetch_assoc($result);
$rights = $row['rights'];
echo "You are now logged in as a {$rights}.";
echo "<br>Welcome!";}

else {
echo "You have typed in an incorrect password or/and username. Please try again."; }}

else {
echo mysql_error();}

?>       

                         

 

Link to comment
Share on other sites

Try structuring your query in a different way.

<?php
require("config.php");

$user = mysql_real_escape_string($_POST['user']);
$pw = md5(sha1(md5(md5($_POST['pw']))));

$query = "SELECT * FROM user_info WHERE username = '$user' and password = '$pw'";
$result = mysql_query($query) or DIE(mysql_error());

if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
$rights = $row["rights"];
echo "You are now logged in as a {$rights}.";
echo "<br />Welcome!";
} else {
echo "You have typed in an incorrect password or/and username. Please try again.";
}
?>

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.