Jump to content

Recommended Posts

Hey all,

I currently have salts being generated. After a salt is generated, I escape the quotes and \ using mysqli_real_escape_string, and then input them into the database.

 

However, I recently ran 100 generations to see the amount of ' " \ that were generated.

http://paste2.org/p/2128924

 

As you can see, ' becomes \', " becomes \", and \ becomes \\.

 

However, my question is how would these extra \ affect loading from the database? Meaning, if I have an external file that were to hash the passwords (using the salt in the database), would any error occur, or would PHP automatically remove the \ when it is being called? After the hashing is complete, would a user be able to log-in without problem, or would they be denied access because their salt contains extra \?

 

 

Thanks for any and all help,

Mark

Link to comment
https://forums.phpfreaks.com/topic/267217-salt-generation-quick-question/
Share on other sites

If the above values are from before inserting into the database, then everything is as it should be and you can (and should) ignore Jet4Fire's suggestion. In fact, in this case his suggestion would undo the escaping, and leave your script open for SQL injections again.

Do note that mysqli_real_escape_string () should only be used directly before using a value in an SQL query, and as such only be saved in that completed query itself. As the escaping makes it unfit to be used anywhere else.

 

If you're unsure about why mysqli_real_escape_string () does what it does, then I recommend reading up on it in the manual and/or other sites which explains output escaping for databases.

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.