Jump to content

[SOLVED] passwrods not matching when clearly they do


mbrown

Recommended Posts

I added a selection box to select the usergroup. When I tried to register I found out that the passwords did not match. I echoed both password1 and password2 out and they were the same.

 

here is the code for register.php

<?php
session_start();
if ($_SESSION['loggedIn'] == TRUE)
{
	include ('./includes/connect.php');
	$username = $_SESSION['username'];
	$userquery = "SELECT * FROM users WHERE username = '$username'";
	$query = mysql_fetch_assoc(mysql_query($userquery));
	if(!$query[usergroup] == "Super Administrator")
	{
		echo "You have to be a super admin";
		//echo "<meta http-equiv='refresh' content='2;url=./administration/index1.php'>";
	}//end of if($query[usergroup] == "Super Administrator")

	else
	{

		$username = $_SESSION['username'];
		echo "User Logged In: $username";
		echo "<br /><a href='./administration/index1.php'>Main Admin</a>";


echo "
		<title>Register</title>

		<style type='text/css'>
		<!--
		.style1 {font-size: 12px}
		.style2 {
			color: #FF0000;
			font-weight: bold;
		}
		-->
		</style>


		<!-- This is the javascript validation needed for the checkbox -->

	</head>

	<body>
		<div align='center'><img src='images/wasdBanner.gif' alt='banner' /></div>


		<noscript>
		<div align='center' class='style2'>You must have javascript enabled<a href='register.php'>Click Here</a> to continue.</div>
		</noscript>


		<form name='registration' method='post' action='./register/validation.php' onsubmit='return agreement(this)'>
		<table border='1' width='50%' cellspacing='0' cellpadding='0' align='center'>



		<tr bgcolor='#f1f1f1'><td align='center' colspan='2'><p><b>Signup</b><br />
		  <b><span class='style1'>Please verify that you have javascript enabled for our website</span><br />
		  </b></p>
		  </td></tr>
		<tr ><td>User ID</td><td><input type='text' name='username' id='username' /></td></tr>

		<tr bgcolor='#f1f1f1'><td >Password</td><td ><input type='password' name='password' /></td></tr>
		<tr ><td >Re-enter Password</td><td ><input type='password' name='password2' /></td></tr>


		<tr bgcolor='#f1f1f1'><td >Email</td><td  ><input type='text' name='email' id='email'/></td></tr>
		<tr ><td >Name</td><td ><input type='text' name='name' /></td></tr>

		<tr ><td >I agree to terms and <a href='terms.php' target='_blank'>conditions</a></td>
		<td ><input type='checkbox' name='agree' value='yes' /></td></tr>
		<tr ><td >UserGroup</td><td >  <select name='Group' id='Group'>
    <option value='	Super Administrator'>	Super Administrator</option>
    <option value='User' selected='selected'>User</option>
  </select>
</td></tr>
		<tr bgcolor='#f1f1f1'><td align='center' colspan='2'><input type='submit' value='Signup' /></td></tr>
		</table>
		<div align='center'><b><a href='http://validator.w3.org/check?uri=referer'><img
				src='http://www.w3.org/Icons/valid-xhtml10'
				alt='Valid XHTML 1.0 Transitional' height='31' width='88' /></a></b>
		</div>
		</form>";

		}
		}

		else
		{
			header("location: ./login.php");
		}

	?>

 

 

here is the code for the register validation

<?php
		//Debugging: echo "test";

		//variables
		$userid = $_POST['username'];
		$password = $_POST['password'];
		$password2 = $_POST['password2'];
		$email = $_POST['email'];
		$name = $_POST['name'];
		$agree = $_POST['agree'];
		$currentDate	=	date("m/d/Y", time());
		$Group = $_POST['Group'];
		$errorMessage = ""; //general error messages
		$failure = ""; //error messages concerning username and email double entry

		$referrer = $_SERVER['HTTP_REFERER'];

		echo "Password1: " . $password . "<br />";
		echo "Password2: " . $password2 . "<br />";

		if ($referrer != "http://localhost/seniorProject/register.php")
		{

			echo "You need to come from 'register.php'";
			echo "<meta http-equiv='refresh' content='2;url=../register.php'>";
		}

		else
		{
			//database connect
			include ("../includes/connect.php");

			//---------------------UserName Lookups----------------------
			//looks to see if the username is all ready registered
			$userquery = "SELECT * FROM users WHERE username = '$userid'";
			$userresult = mysql_query($userquery) or die (mysql_error());
			$usernumrows = mysql_num_rows($userresult);
			if ($usernumrows > 0)
			{
				$failure .= "$userid, is currently registered with our system.<br />";
			}

			//---------------------Email Lookups----------------------
			//looks to see if the e-mail is already registered wit the system.
			$emailquery = "SELECT * FROM users WHERE email = '$email'";
			$emailresult = mysql_query($emailquery) or die (mysql_error());
			$emailnumrows = mysql_num_rows($emailresult);
			//Debugging: echo $emailnumrows . "<br />";
			if ($emailnumrows > 0)
			{
				$failure .= "$email, is already registered";
			}

			//-----Failure loop-----------------------------
			if ($failure)
			{
				echo $failure;
			}

			//-----------general errors-------------------------
			else
			{		

				//check to see if the username is registered
				if (strlen($userid) < 5 || strlen($userid) > 20)
				{
					$errorMessage .= "Please enter a longer username. Usernames must be between 5 and 20 characters";
				}//end of if (strlen($userid) < 5 || strlen($userid) > 20)

				if ($password != $passsword2)
				{
					$errorMessage .= "<br />You have not entered the same password twice. Please try again.";
				}//end of if ($password != $passsword2)


				if (!$errorMessage)
				{
					$dbpassword = sha1($password);

					include ("../includes/adduser.php");

					include ("../includes/newusermailer.php");

					echo "<br />";
					echo "Thank you $name, for registering on our Asset Tracking System.";
					echo "Your log-in information is listed below and has also been sent to you";
					echo "<br />";
					echo "Username: $userid";
					echo "<br />";
					echo "Password: $password";

				}//end of if (!$error)

				else
				{
					echo $errorMessage;

					//include form

				}//end of else
			}
		}
	?>


Test if the two passwords are the same when you do the validation rather than at the beginning.

 

<?php
               echo "{$password}<br/>{$password2}";

               if ($password != $passsword2)
               {
                  $errorMessage .= "<br />You have not entered the same password twice. Please try again.";
               }//end of if ($password != $passsword2)
               
?>

 

You may be changing one of the variables before the validation but after the debugging test you've placed yourself.

 

Also, just to let you know, if you want to check that something is not equal to something else you do it like this:

 

<?php
// Add single quotations to your array and use != rather than !$x == 'xxx'
if( $query['usergroup'] != "Super Administrator" )

// Not if( !$query[usergroup] == "Super Administrator" )
?>

The second thing you stated I fixed

 

The passwords I get the following:

 

mike

mike

You have not entered the same password twice. Please try again. //from your validation

You have not entered the same password twice. Please try again. //from my validation

 

could it be a cache/cookie issue?

Archived

This topic is now archived and is closed to further replies.

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