Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>firstly: MD5 is a <a href="http://en.wikipedia.org/wiki/Cryptographic%5Fhash%5Ffunction" rel="nofollow noreferrer">cryptographic hash function</a>, not necessarily an encryption method. A hash is designed to only be performed in one direction, and cannot be reversed. (this is a good thing)</p> <p>MD5 is however cryptographically broken (not considered secure anymore); you should use another hash function (preferable Bcrypt-hash or at least SHA256)</p> <p>Looking at the code, I can see several things wrong:</p> <ol> <li>your password is not <a href="http://en.wikipedia.org/wiki/Salt_%28cryptography%29" rel="nofollow noreferrer">salted</a></li> <li>I really hope that <code>$typed_password</code> is properly sanitized or you are in for <a href="https://stackoverflow.com/questions/601300/what-is-sql-injection">SQL-injection</a>.</li> <li>You try to select all users from the table with the same password.</li> </ol> <p>The easiest (and probably best) way of doing passwords is by using a standard library: the <a href="http://www.openwall.com/phpass/" rel="nofollow noreferrer"><strong>Portable PHP password hashing framework</strong></a> and make sure you use the <code>CRYPT_BLOWFISH</code> algorithm.</p> <pre><code>require('PasswordHash.php'); $pwdHasher = new PasswordHash(8, FALSE); // $hash is what you would store in your database $hash = $pwdHasher-&gt;HashPassword( $password ); // $hash would be the $hash stored in your database for this user $checked = $pwdHasher-&gt;CheckPassword($password, $hash); if ($checked) { echo 'password correct'; } else { echo 'wrong credentials'; } </code></pre> <p>the store/check/update queries should be bound to the user's Id:</p> <pre><code>// Insert query $query = "INSERT INTO users VALUES({$userId}, '{$username}', '{$hash}')"; // Select query $query = "SELECT hash FROM users WHERE userId = {$userId}"; // Update query $query = "UPDATE users SET hash = '{$hash}' WHERE userId = {$userId}"; </code></pre> <p>And then, you should use <a href="https://stackoverflow.com/questions/60174/best-way-to-stop-sql-injection-in-php">parametrised queries</a> instead of directly passing the variable values into the query.</p> <p>I realise this is a lot of info at once, but it is vital learn this if you do not want your script to be hackable by almost every programmer out there.</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