Jump to content

update password script


WatsonN

Recommended Posts

I have a script to let the user update their password, when I submit it i get a 500 error and I'm not sure.

 

Here is the code:

If (isset($_POST['update-password'])) {
 	//This makes sure they did not leave any fields blank
if (!$_POST['oldpw'] || !$_POST['pass'] || !$_POST['pass2'] ) {
		$error="<span style=";
	$error .="color:red";
	$error .=">";
		$error .= "You did not complete all of the required fields";
		$error .="</span>";
		setcookie('Errors', $error, time()+20);
	header('Location /useredit.php');
	exit;
	}

// checks if the password is correct
	$pass = md5($_POST['pass']);
	if (!get_magic_quotes_gpc()) {
		$pass = addslashes($pass);
	}
		$check = mysql_real_escape_string("SELECT * FROM YBK_Login WHERE pass = '{$pass}'");
mysql_query($check) or die( 'Query string: ' . $check . '<br />Produced an error: ' . mysql_error() . '<br />' );


// this makes sure both passwords entered match
	if ($_POST['pass'] != $_POST['pass2']) {
		$error="<span style=";
	$error .="color:red";
	$error .=">";
		$error .= 'Your passwords did not match.';
		$error .="</span>";
		setcookie('Errors', $error, time()+20);
	header('Location: /useredit.php');
	exit;
	}

	// here we encrypt the password and add slashes if needed
	$_POST['pass'] = md5($_POST['pass']);
	if (!get_magic_quotes_gpc()) {
		$_POST['pass'] = addslashes($_POST['pass']);
		$_POST['pass2'] = addslashes($_POST['pass2']);
			}


// now we insert it into the database
mysql_real_escape_string($insert = "UPDATE `YBK_Login` SET `pass` = '{$_POST['pass']}', `HR` = '{$_POST['pass2']}', `comment` = '{$_POST['oldpw']}' WHERE `ID` = {$_COOKIE['UID_WatsonN']}");
mysql_query($insert) or die( 'Query string: ' . $insert . '<br />Produced an error: ' . mysql_error() . '<br />' );
 $error="<span style=";
 $error .="color:green";
 $error .=">";
 $error .= "<p>Thank you, your password has been updated.</p>";
 $error .="</span>";
 setcookie('Errors', $error, time()+20);
 header('Location: /useredit.php');
 exit;
  } 

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.