Jump to content

SALT help?


Tenaciousmug

Recommended Posts

Ok this is my script so far:

class User {

function generateHash($password, &$saluti=null) {
	define('SALT_LENGTH', 15);

	$key = '!@#$%^&*()_+=-{}][;";/?<>.,';
	if ($saluti=="")
	{
		$saluti = substr(hash('sha512', uniqid(rand(), true).$key.microtime()), 0, SALT_LENGTH);
	}
	else
	{
		$saluti = substr($saluti, 0, SALT_LENGTH);
	}

	return hash('sha512', $saluti . $key . $password);
}

function validate_user($username,$password) {
	$mysql = new Database();
	$hashedPassword = generateHash($password,'');
	$ensure_credentials = $mysql->verify_username_and_password($username,$hashedPassword);

	if($ensure_credentials) {
		$_SESSION['auth'] == "yes";
		header("Location: index.php");
	}
	else
		return "That was not the correct username or password.";
}

}

 

It gives me this error:

[05-Feb-2012 17:14:59] PHP Fatal error:  Call to undefined function  generatehash() in /home1/elvonica/public_html/scripts/classes/user.php on line 24

 

Can anyone help me solve this?

Link to comment
Share on other sites

even if i change it to generate_hash in both places, it still gives me the error message:

[05-Feb-2012 19:47:31] PHP Fatal error:  Call to undefined function  generate_hash() in /home1/elvonica/public_html/scripts/classes/user.php on line 24

 

The capitalization isn't what's going on. Because in both places I had generateHash. But it just converted it to lowercase. Now I have lowercase, still same error.

Anyone?

Link to comment
Share on other sites

No idea what cooldood just said, but heres your problem:

 

1. The function is inside User class, therefore you must use $this->generateHash()

Btw since the function is same for all instances of the User object you might as well make it static and call it self::generateHash()

 

2. You cant assign variable reference without variable.

Your function definition:

function generateHash($password, &$saluti=null)

 

Your call:

$this->generateHash($password,'')

 

This will return fatal error. Either remove the variable reference tag (&) or pass a variable to the function.

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.