note 45350 deleted from function.crypt by googleguy

From: Date: Sat, 06 Feb 2016 07:38:49 +0000
Subject: note 45350 deleted from function.crypt by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-204883@lists.php.net to get a copy of this message
Note Submitter: thorhajo at gmail dot com ---- Here's a little function I wrote to generate MD5 password hashes in the format they're found in /etc/shadow: function shadow($password) { $hash = ''; for($i=0;$i<8;$i++) { $j = mt_rand(0,53); if($j<26)$hash .= chr(rand(65,90)); else if($j<52)$hash .= chr(rand(97,122)); else if($j<53)$hash .= '.'; else $hash .= '/'; } return crypt($password,'$1$'.$hash.'$'); } I've written this so that each character in the a-zA-Z./ set has a 1/54 of a chance of being selected (26 + 26 + 2 = 54), thus being statistically even.

« previous php.notes (#204883) next »