473,378 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Password and confirmation passw not equal after submit

65
Hi friends,
I'm writing a login.php script.
I stored the password in mysql db as encrypted format using md5.
(It's in registration.php and it works well).
There is a no problem in registering new users.

When the login form exists, the password and confirm password didn't match always. It shows only "Password didn't match, plz try again".

Can anyone help me.....??? The code which wrongly works is as follows:

while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
if ($_POST['pass'] != $info['password'])
{
die('Incorrect password, please try again.');
}
else
{
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
header("Location: members.php");
}
}

Plz... Tell me the correct code soon...
Feb 13 '08 #1
10 5352
hsriat
1,654 Expert 1GB
Hi friends,
I'm writing a login.php script.
I stored the password in mysql db as encrypted format using md5.
(It's in registration.php and it works well).
There is a no problem in registering new users.

When the login form exists, the password and confirm password didn't match always. It shows only "Password didn't match, plz try again".

Can anyone help me.....??? The code which wrongly works is as follows:

while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
if ($_POST['pass'] != $info['password'])
{
die('Incorrect password, please try again.');
}
else
{
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
//header("Location: members.php");//temporarily disable this.
}
}

Plz... Tell me the correct code soon...
I couldn't find any reason for the error...
You can though do one thing...
Just before comparing the passwords, echo both the passwords and see whats the reason.
[PHP]while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);

//add this temporarily
echo "DB password=".$info['password']."<br>Submitted password=".$_POST['pass']."<br>md5 of submitted=";


$_POST['pass'] = md5($_POST['pass']);

//this too
echo $_POST['pass'];

if ($_POST['pass'] != $info['password'])
{
die('Incorrect password, please try again.');
}
else
{
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
header("Location: members.php");
}
}[/PHP]

Also I don't think its a good idea to save password in db in md5. Use md5 just to save password in cookie. And take md5 of password in db each time you compare it with the cookie's password.

Do ask some senior person too, I'm not sure if its a better way. Do tell me also if its not the right way.
Feb 13 '08 #2
Markus
6,050 Expert 4TB
Actually, it is best practise to save the md5()'d password into the database, as this if someone were to crack the database, they wouldn't be able to use the passwords. :)

Not even you, the webmaster, should be able to see what the passwords are.
Feb 13 '08 #3
ronverdonk
4,258 Expert 4TB
Apart from the correct use of MD5 values and $_POST arrays to store temp values:

Are you sure that $info['password'] is already MD5-ed?
Because you compare an MD5 result value in $_POST['pass'] with it.

Ronald
Feb 13 '08 #4
yasmine
65
Hi friends,
I'm writing a login.php script.
I stored the password in mysql db as encrypted format using md5.
(It's in registration.php and it works well).
There is a no problem in registering new users.
When the login form exists, the password and confirm password didn't match always. It shows only "Password didn't match, plz try again".
The whole code for login.php which I wrote is as follows:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  mysql_connect("localhost", "root", "") or die(mysql_error());
  3.  mysql_select_db("mydb") or die(mysql_error());
  4.  if(isset($_COOKIE['ID_my_site']))
  5.  {
  6.   $username = $_COOKIE['ID_my_site'];
  7.   $pass = $_COOKIE['Key_my_site'];
  8.   $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
  9.   while($info = mysql_fetch_array( $check ))
  10.   {
  11.    if ($pass != $info['password'])
  12.    {
  13.    }
  14.    else
  15.    {
  16.     header("Location: members.php");
  17.    }
  18.   }
  19.  }
  20.  if (isset($_POST['submit']))
  21.  {
  22.   if(!$_POST['username'] | !$_POST['pass'])
  23.   {
  24.    die('You did not fill in a required field.');
  25.   }
  26.   $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
  27.   $check2 = mysql_num_rows($check);
  28.   if ($check2 == 0)
  29.   {
  30.    die('That user does not exist in our database.
  31.    <a href=register.php>Click Here to Register</a>');
  32.   }
  33.   while($info = mysql_fetch_array( $check ))
  34.   {
  35.    $_POST['pass'] = stripslashes($_POST['pass']);
  36.    $info['password'] = stripslashes($info['password']);
  37.    $_POST['pass'] = md5($_POST['pass']);
  38.    if ($_POST['pass'] != $info['password'])
  39.    {
  40.     die('Incorrect password, please try again.');
  41.    }
  42.    else
  43.    {
  44.     $_POST['username'] = stripslashes($_POST['username']);
  45.     $hour = time() + 3600;
  46.     setcookie(ID_my_site, $_POST['username'], $hour);
  47.     setcookie(Key_my_site, $_POST['pass'], $hour);
  48.     header("Location: members.php");
  49.    }
  50.   }
  51.  }
  52.  else
  53.  {
  54. ?>
  55.  
  56. <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  57. <table border="0">
  58. <tr>
  59.    <td colspan=2>
  60.       <h1>Login</h1>
  61.    </td>
  62. </tr>
  63. <tr>
  64.    <td>Username:</td>
  65.    <td>
  66.       <input type="text" name="username" maxlength="40">
  67.    </td>
  68. </tr>
  69. <tr><td>Password:</td>
  70.   <td>
  71.     <input type="password" name="pass" maxlength="50">
  72.   </td>
  73. </tr>
  74. <tr>
  75.   <td colspan="2" align="right">
  76.   <input type="submit" name="submit" value="Login">
  77.   </td>
  78. </tr>
  79. </table>
  80. </form>
  81. <?php
  82. }
  83.  
  84. ?>
Cany any one tell me what is the wrong with this code...???
Feb 14 '08 #5
dlite922
1,584 Expert 1GB
You read this: http://www.thescripts.com/forum/faq....ask_a_question

while i read your code:


[PHP]
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());
if(isset($_COOKIE['ID_my_site']))
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
}
else
{
header("Location: members.php");
}
}
}
if (isset($_POST['submit']))
{
if(!$_POST['username'] | !$_POST['pass'])
{
die('You did not fill in a required field.');
}
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
$check2 = mysql_num_rows($check);
if ($check2 == 0)
{
die('That user does not exist in our database.
<a href=register.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
if ($_POST['pass'] != $info['password'])
{
die('Incorrect password, please try again.');
}
else
{
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
header("Location: members.php");
}
}
}
else
{
?>

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr>
<td colspan=2>
<h1>Login</h1>
</td>
</tr>
<tr>
<td>Username:</td>
<td>
<input type="text" name="username" maxlength="40">
</td>
</tr>
<tr><td>Password:</td>
<td>
<input type="password" name="pass" maxlength="50">
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
</td>
</tr>
</table>
</form>
<?php
}

?>

[/PHP]
Feb 14 '08 #6
yasmine
65
Thank U very much.
As i'm new to this site, i didn't know the rules n regulations...
I never do this again.
Thanks again...
Feb 14 '08 #7
ronverdonk
4,258 Expert 4TB
Then I suggest you read the Posting Guidelines before you continue!. You have already 16 posts so you are not that new!

Btw this is a double thread from <removed n/a link>

Read the posting guidelines and stop wasting anybody's time with it.

Ronald
Feb 14 '08 #8
RedSon
5,000 Expert 4TB
Merged.

Please follow the rules or your account may get banned.

Thanks

-Moderator
Feb 14 '08 #9
yasmine
65
Then I suggest you read the Posting Guidelines before you continue!. You have already 16 posts so you are not that new!

Btw this is a double thread from <removed n/a link>

Read the posting guidelines and stop wasting anybody's time with it.

Ronald

Thanx.....
I read it and I'm following......
Can u tell me what is meant by PM questions???
Feb 15 '08 #10
Markus
6,050 Expert 4TB
Thanx.....
I read it and I'm following......
Can u tell me what is meant by PM questions???
Private Messages.
Click on the users profile link, and follow the link to provate messaging,
Feb 15 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Lakshmi Narayanan | last post by:
Hi experts, My problem is, for password <input name="password" type="password"> element the size given is 20. For another one <input name="username"> is also 20. But in browser the size differs...
7
by: Mike | last post by:
I've been trying for the past week to put a simple code together. I have done a LOT of searching, found scripts showing the functions I would like to use, however when I mix them it all goes wrong,...
6
by: Nedu N | last post by:
Hi, I want to have confirmation(Yes/No) on a button of the webform in which there are many validation controls. I want all the validation controls to be triggered first and then Yes/No...
3
by: Funky | last post by:
Hi, I have developed an ASP.NET application which has been running in production for around 3 months without any major glitches. Recently, a user was attempting to upload a rather large CSV file...
5
by: Skeleton Man | last post by:
Hi, I came across the basic algorithmfor decrypting WS_FTP Pro 6 passwords as follows, and I'm trying to reverse it to make an encryption function: function ws_dec() { var str =...
2
by: bay_dar | last post by:
Hi, I have an internal ASP.NET application that I'm are using to send e-mails out based on a single milepost or milepost range entered. I'm trying to do two things when a user clicks on the...
2
by: wesomon99 | last post by:
I'm designing a server-side application to accept query strings from PDF documents. The user clicks a link in the document to submit some information (i.e....
7
by: hotflash | last post by:
Hi All, I want to creat a script where I will allow user to reset their own password. I have tried different options but don't have any luck. Wonder what I want to do is kinda not valid or not. ...
7
Haitashi
by: Haitashi | last post by:
I had the following code that would create a javascript confirmation page. This code lived inside a form which wouldn't submit until the user clicked the Ok button. <input type="image"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.