Jump to content

Code Help


darkfreaks

Recommended Posts

ok i messed something up trying to add validation but can anyone see where i messed up? i will comment the lines that error. which is 163-165 and 319 i get headers cannot be moddified previously sent. ???

 

<?php
/**
 * Checks the password code via the GET method
 * @return true if valid false if not
 */
function check_password_code() {
$code = $this->qls->Security->make_safe($_GET['code']);
$result = $this->qls->SQL->select('*',
	'password_requests',
	array('code' =>
		array(
			'=',
			$code
		)
	)
);
$row = $this->qls->SQL->fetch_array($result);
	if ($row['id'] != '' && $row['used'] != 1) {
	return true;
	}
	else {
	return false;
	}
}

/**
 * This will actually change the password of the user
 * @return true on success, false on failure
 */
function change_password() {
	// A little extra security
	if ($this->check_password_code()) {
	$code = $this->qls->Security->make_safe($_GET['code']);

	// Retrieve the information from the database
	$result = $this->qls->SQL->select('*',
		'password_requests',
		array('code' =>
			array(
				'=',
				$code
			)
		)
	);
	$row = $this->qls->SQL->fetch_array($result);

	// Get the user's username from the database
	$users_result = $this->qls->SQL->select('*',
		'users',
		array('id' =>
			array(
				'=',
				$row['user_id']
			)
		)
	);
	$users_row = $this->qls->SQL->fetch_array($users_result);

	$new_password = (isset($_POST['new_password']) && $this->validate_password($_POST['new_password'])) ? $this->qls->Security->make_safe($_POST['new_password']) : false;
	$new_password_confirm = (isset($_POST['new_password_confirm']) && $_POST['new_password_confirm'] == $_POST['new_password']) ? true : false;
		if ($new_password !== false && $new_password_confirm !== false) {
		$password_hash = $this->generate_password_hash($new_password, $users_row['username'], $users_row['code']);

		// Update the database
		$this->qls->SQL->update('users',
			array('password' => $password_hash),
			array('id' =>
				array(
					'=',
					$row['user_id']
				)
			)
		);
		$this->qls->SQL->update('password_requests',
			array('used' => 1),
			array('id' =>
				array(
					'=',
					$row['id']
				)
			)
		);
		return true;
		}
		else {
		$this->change_password_error = REGISTER_PASSWORD_ERROR;
		return false; //163
		}//164
	else {//165
	$this->change_password_error = CHANGE_PASSWORD_INVALID_CODE;
	return false;
	}
}?>

 

and:

 

 

<?php
function validate_username($input) {
	if (preg_match($this->qls->config['user_regex'], $input)) {
		if (strlen($input) <= $this->qls->config['max_username'] &&
			strlen($input) >= $this->qls->config['min_username']) {
		return true;
		}
		else {
		return false;
		}
	}
	else {
	return false;	
	}//319
}?>

Link to comment
https://forums.phpfreaks.com/topic/90372-code-help/
Share on other sites

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.