SELECT *, LENGTH( pw_encrypted), LENGTH( pw_hash_encrypted) FROM forum WHERE id = 1;
stdClass Object ( [id] => 1 [username] => Harald [password] => Wachtwoord [pw_hash] => $2y$10$e3vbY7w1Vd9EIjn3Df/MEeYleIqCozb1c8grNy8wSa0HThFWy7Jqi [pw_encrypted] => 87E18F70A7E21A15040644BCB1FE312A [pw_hash_encrypted] => 5DAFF5F8E186828B5AE0D269D453887D82F06CDA7EB7AD71FAE452024F6B266BBDA19093F76EF6B310C86C2660157EB4AFA2AC0DE083D3AFE6588DC82A44BED4 [LENGTH( pw_encrypted)] => 32 [LENGTH( pw_hash_encrypted)] => 128 )
In plaats van het password kan ook de hash van het wachtwoord worden encrypt.
In werkelijkheid wordt het wachtwoord NIET leesbaar bewaard.
In het geval de database wordt gejat, moet eerst de encrypted hash worden decrypt alvorens de hash zelf kan worden gekraakt.
De $SQL_encrypt_key variable moet op een veilige plek worden bewaard. De meningen verschillen over waar die veilige plek dan wel is.
➠ https://mariadb.com/kb/en/aes_encrypt/
➠ De toelichting voor het geval dat u ’m gemist heeft.
$query = "UPDATE forum
SET pw_hash = '" . $pw_hash . "',
pw_encrypted = HEX( AES_ENCRYPT( password, '" . $SQL_encrypt_key . "' ) ),
pw_hash_encrypted = HEX( AES_ENCRYPT( pw_hash, '" . $SQL_encrypt_key . "' ) )
WHERE id = 1;";
UPDATE forum
SET
pw_hash = "$2y$10$LP7E/bUPbL.d2hII.J5nFuGNRiQekWjTzBZDhVv7G6LgbIMNVMAem",
pw_encrypted = HEX( AES_ENCRYPT( password, "Carthago Delenda Est" ) ),
pw_hash_encrypted = HEX( AES_ENCRYPT( pw_hash, "Carthago Delenda Est" ) )
WHERE id = 1;
SELECT id, username, password, pw_hash, pw_encrypted, pw_hash_encrypted, AES_DECRYPT( UNHEX( pw_encrypted ), "Carthago Delenda Est" ) AS pw_decrypted, AES_DECRYPT( UNHEX( pw_hash_encrypted ), "Carthago Delenda Est" ) AS pw_hash_decrypted FROM forum WHERE id = 1;
ID | 1 |
Username | Harald |
password | Wachtwoord |
hash | $2y$10$LP7E/bUPbL.d2hII.J5nFuGNRiQekWjTzBZDhVv7G6LgbIMNVMAem |
pw_encrypted | 87E18F70A7E21A15040644BCB1FE312A |
pw_decrypted | Wachtwoord |
pw_hash_encrypted | 8396961810B83790C7F1EBE3F9ADE8D033D680245ADB402070C8B2846029F2E9BEFEC82926C77E3A4C1E4548A69986464A12788AC41118D7AAC03F68B99089C8 |
pw_hash_decrypted | $2y$10$LP7E/bUPbL.d2hII.J5nFuGNRiQekWjTzBZDhVv7G6LgbIMNVMAem |
password is | Valid |