Jump to content

Password Salting problem :/


Go to solution Solved by cyberRobot,

Recommended Posts

Hi, I've got some issues with my salting when I register... basically everything works fine apart from the salting and I can't get my head around it?

 

Here's my php register function:

public function register() {
		$correct = false;
			try {
				$con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
				$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
				$sql = "INSERT INTO list_members(username, email, password) VALUES(:username, :email, :password)";
				
				$stmt = $con->prepare( $sql );
				$stmt->bindValue( "username", $this->username, PDO::PARAM_STR );
				$stmt->bindValue( "email", $this->email, PDO::PARAM_STR );
				$stmt->bindValue( "password", hash("sha256", $this->password . $this->salt), PDO::PARAM_STR );
				$stmt->execute();
				return header('Location: index.html');
			}catch( PDOException $e ) {
				return $e->getMessage();
			}
	 }

And then I have my public variables displayed like this: 

         public $username = null;
	 public $email = null;
	 public $password = null;
	 public $salt = "Zo4rU5Z1YyKJAASY0PT6EUg7BBYdlEhPaNLuxAwU8lqu1ElzHv0Ri7EM6irpx5w";

Help would be much appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/279243-password-salting-problem/
Share on other sites

  • Solution

Oh sorry, the problem is that the salt isn't being added to the database, it's just left blank.

 

Are you looking to store the salt in the database with each user record? If so, you need to modify the query to include the salt. It currently only references username, e-mail, and password.

 

 

$sql = "INSERT INTO list_members(username, email, password) VALUES(:username, :email, :password)";

 

Are you looking to store the salt in the database with each user record? If so, you need to modify the query to include the salt. It currently only references username, e-mail, and password.

$sql = "INSERT INTO list_members(username, email, password) VALUES(:username, :email, :password)";

 

 

Ah that's it, I must of missed it out xD Thanks for the help.

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.