<?php
define ( 'PASSWORD_ENCRYPTION' , "bcrypt" ) ; define ( 'PASSWORD_SHA512_ITERATIONS' , 25000 ) ; define ( 'PASSWORD_BCRYPT_COST' , "13" ) ;
define ( 'PASSWORD_SALT' , "/8Wncr26eAmxD1l6cAF9F8" ) ; //22 characters to be appended on first 7 characters that will be generated using PASSWORD_ info above // your code goes here
echo hashPassword( "test123abc" ) ;
function hashPassword( $password ) {
//this salt will be used in both algorithms
//for bcrypt it is required to look like this,
//for sha512 it is not required but it can be used
$salt = "$2a $" . PASSWORD_BCRYPT_COST . "$" . PASSWORD_SALT;
if ( PASSWORD_ENCRYPTION == "bcrypt" ) {
$newPassword = crypt ( $password , $salt ) ; }
else {
$newPassword = $password ;
for ( $i = 0 ; $i < PASSWORD_SHA512_ITERATIONS; $i ++ )
$newPassword = hash ( 'sha512' , $salt . $newPassword . $salt ) ; }
return $newPassword ;
}
?>
PD9waHAKZGVmaW5lKCdQQVNTV09SRF9FTkNSWVBUSU9OJywgImJjcnlwdCIpOyAKZGVmaW5lKCdQQVNTV09SRF9TSEE1MTJfSVRFUkFUSU9OUycsIDI1MDAwKTsgCmRlZmluZSgnUEFTU1dPUkRfQkNSWVBUX0NPU1QnLCAiMTMiKTsgCgpkZWZpbmUoJ1BBU1NXT1JEX1NBTFQnLCAiLzhXbmNyMjZlQW14RDFsNmNBRjlGOCIpOyAvLzIyIGNoYXJhY3RlcnMgdG8gYmUgYXBwZW5kZWQgb24gZmlyc3QgNyBjaGFyYWN0ZXJzIHRoYXQgd2lsbCBiZSBnZW5lcmF0ZWQgdXNpbmcgUEFTU1dPUkRfIGluZm8gYWJvdmUKLy8geW91ciBjb2RlIGdvZXMgaGVyZQoKZWNobyBoYXNoUGFzc3dvcmQoInRlc3QxMjNhYmMiKTsKCiBmdW5jdGlvbiBoYXNoUGFzc3dvcmQoJHBhc3N3b3JkKSB7CiAgICAvL3RoaXMgc2FsdCB3aWxsIGJlIHVzZWQgaW4gYm90aCBhbGdvcml0aG1zC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