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:

  Quote
[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
https://forums.phpfreaks.com/topic/256501-salt-help/
Share on other sites

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

  Quote
[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
https://forums.phpfreaks.com/topic/256501-salt-help/#findComment-1314959
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
https://forums.phpfreaks.com/topic/256501-salt-help/#findComment-1315097
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.