Toon records

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$62e1aaBRspirdIRfmL/0xe7y3N/rkyfk5ScW/QPhUiSxxywsSHL7m
    [pw_encrypted] => 87E18F70A7E21A15040644BCB1FE312A
    [pw_hash_encrypted] => F9D823FB0BBB08F8F246394D9960AA1FD619EFE14C3BE006F92B759380FB07A57AA1B7F7061156F521E812A864C054AF1D8F4AE0E0E0D681B27BED631DE23CE6
    [LENGTH( pw_encrypted)] => 32
    [LENGTH( pw_hash_encrypted)] => 128
)

Toon records NA UPDATE

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.

Download deze PHP bestanden

$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$NYmPEQ4NJNr95G4MHp6ha.LrIrNbzIpCqZVzsk/DPNVKK.TJ2r7wS", pw_encrypted = HEX( AES_ENCRYPT( password, "Carthago Delenda Est" ) ), pw_hash_encrypted = HEX( AES_ENCRYPT( pw_hash, "Carthago Delenda Est" ) ) WHERE id = 1;

Parse encrypted

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;

ID1
UsernameHarald
passwordWachtwoord
hash$2y$10$NYmPEQ4NJNr95G4MHp6ha.LrIrNbzIpCqZVzsk/DPNVKK.TJ2r7wS
 
pw_encrypted87E18F70A7E21A15040644BCB1FE312A
pw_decryptedWachtwoord
pw_hash_encrypted20D963A5FB33C77376C87E26D0262CB6571AEE414AE2B631634B7B4C1D79D12F2994D7B741C61C0E146E5EB216095003D6823400783722E3A10064E55FAE53FE
pw_hash_decrypted$2y$10$NYmPEQ4NJNr95G4MHp6ha.LrIrNbzIpCqZVzsk/DPNVKK.TJ2r7wS
 
password is Valid