Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, the question is actually a very good one. There is one way to ensure this kind of problems dont happen though. But first i'd like to clear out the difference between hashing and encrypting</p> <p>Hashing is when we convert the subject into a long hash. This is very hard to reverse and requires a lot of resources to do it. We usually hash passwords e.t.c. Encrypting is when we want to store data securely but want to be able to get it back, we convert it into another long thing but we can also reverse it easily(If we know the key)</p> <p>You can use what is called a 'salt' to protect hashes like your password, since we know that Hash(x) is gonna be VERY different from Hash(x+y), we can use that. Although i wouldnt use MD5 if i were you, it is still great but collisions have been seen in it(A lot of hashing algorithms have them, but being found reduces their security). I recommend you use sha256/sha512. They are very secure and no known collisions have been seen in them so far.</p> <p>Me being nerdy aside, your problem is very simple. I am going to use the <a href="http://php.net/manual/en/function.hash.php" rel="nofollow">hash function of php</a> in my example. Since you said the usernames are unique, you can use this for a very safe hashing system</p> <pre><code>$password = YOUR_PASSWORD_HERE; $username = USERNAME_OF_USER; $safe_hash = hash("sha512",$password.$username); </code></pre> <p>This merges the two username and password and hashes them with the sha512 algorithm(Change the algorithm if you want). This is very safe as 'password'.'user1' is having a unique and different hash than 'password'.'user2'</p> <p>If you want to make it even more secure, you can add other stuff like creation times, last names,first names, mobile number, email, creation time, anything that you know and is preferably unique really.</p> <p>As for encrypting the data(So that you can get it back if you want to) you can use mcrypt. You can use <a href="http://php.net/manual/en/function.mcrypt-encrypt.php" rel="nofollow">mcrypt_encrypt</a> and <a href="http://php.net/manual/en/function.mcrypt-decrypt.php" rel="nofollow">mcrypt_decrypt</a>. You can specify the <a href="http://php.net/manual/en/mcrypt.ciphers.php" rel="nofollow">cipher</a> you want to use and also the <a href="http://php.net/manual/en/book.mcrypt.php" rel="nofollow">mode</a> you want to use. Then when you want your data back, you can again give mcrypt the key, algorithm, mode and the nonsense output that mcrypt_encrypt gave you and you'll have your original data.</p> <p>I recommend using a very secure key by using hashes, since its very hard to reverse engineer them. Using a sha-256 hash with a good and unique string(I recommend mixing multiple pieces of data in the hash string) will help you secure the data needed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload