fork(7) download
  1. <?php
  2. define('PASSWORD_ENCRYPTION', "bcrypt");
  3. define('PASSWORD_SHA512_ITERATIONS', 25000);
  4. define('PASSWORD_BCRYPT_COST', "13");
  5.  
  6. define('PASSWORD_SALT', "/8Wncr26eAmxD1l6cAF9F8"); //22 characters to be appended on first 7 characters that will be generated using PASSWORD_ info above
  7. // your code goes here
  8.  
  9. echo hashPassword("test123abc");
  10.  
  11. function hashPassword($password) {
  12. //this salt will be used in both algorithms
  13. //for bcrypt it is required to look like this,
  14. //for sha512 it is not required but it can be used
  15. $salt = "$2a$" . PASSWORD_BCRYPT_COST . "$" . PASSWORD_SALT;
  16.  
  17. if(PASSWORD_ENCRYPTION == "bcrypt") {
  18. $newPassword = crypt($password, $salt);
  19. }
  20. else {
  21. $newPassword = $password;
  22. for($i=0; $i<PASSWORD_SHA512_ITERATIONS; $i++)
  23. $newPassword = hash('sha512',$salt.$newPassword.$salt);
  24. }
  25.  
  26. return $newPassword;
  27. }
  28.  
  29. ?>
Success #stdin #stdout 0.63s 20568KB
stdin
Standard input is empty
stdout
$2a$13$/8Wncr26eAmxD1l6cAF9FuVnazDlahXc73He5NB1GKNYG7v3mOOyS