salt - PHP Class Function for hashing -



salt - PHP Class Function for hashing -

public function kryptonite($string){ $salt = ""; $salt_vars = array_merge(range("a","z"),range("a","z"),range(0,9)); for($i=0;$i < 22;$i++){ $salt.= $salt_vars[array_rand($salt_vars)]; } homecoming crypt($string, '$6$'.$salt); }

this returns on refresh:

$6$vnuqcea70$chwmpvsdvb.lvpq1pnsdn7.0fsmbx6fu2plofk6djoh7fqp6edssde3aw6to8fy1l01/wocwz8oie0oxk1ltj. $6$7lmp9sd4g$i0facdjno2lf255gg6txtlt9trwr803zxiu9bowjxhwrgbjdpj3lvaw9w2kbrz/3edssbfrgf7rv7ddb0vlia0

if closely @ first few lines it's changing constantly. don't think hashing suppose change! technically i'll never able test against this. can help me kryptonite crypt function or explain me went wrong really.

as matter of fact, hashing is supposed randomly alter - it's called random salting. crypt function creating random salt fed sha-512 hasher.

the output of crypt() includes salt value, utilize when hashing password compare stored hash.

public function kryptonite($string, $salt = null){ if ($salt === null) { $salt = ""; $salt_vars = array_merge(range("a","z"),range("a","z"),range(0,9)); for($i=0;$i < 22;$i++){ $salt.= $salt_vars[array_rand($salt_vars)]; } $salt = '$6$' . $salt; } homecoming crypt($string, $salt); }

to utilize this, you'd following:

$storedhash = '.....'; // fetched database $inputpassword = '.....'; // user $salt = preg_match('/\$[0-9]\$(.+)\$/')[1]; // php 5.4+ if (kryptonite($inputpassword, $salt) == $storedhash) { //.... success }

note array_random implementation of creating random salt isn't cryptographically secure - it'd improve utilize openssl_random_pseudo_bytes() or mt_rand() or such.

php salt crypt

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -