5) { $algorithm = 4; /* default to SHA-256 */ } if ($algorithm == 0) { $algorithmName = "APR1-MD5"; $saltLength = 8; $salt = CreateSalt($saltLength); $cryptsalt = '$apr1$'.$salt; } if ($algorithm == 1) { $algorithmName = "MD5"; $saltLength = 8; $salt = CreateSalt($saltLength); $cryptsalt = '$1$'.$salt; } if ($algorithm == 2) { $algorithmName = "SHA-1"; $cryptsalt = "{SHA}"; } if ($algorithm == 3) { $algorithmName = "Blowfish"; $saltLength = 22; $salt = CreateSalt($saltLength); $cryptsalt = $bPrefix . $bCost . '$' . $salt; } if ($algorithm == 4) { $algorithmName = "SHA-256"; $saltLength = 16; $salt = CreateSalt($saltLength); $cryptsalt = '$5$'.$salt; } if ($algorithm == 5) { $algorithmName = "SHA-512"; $saltLength = 16; $salt = CreateSalt($saltLength); $cryptsalt = '$6$'.$salt; } /* call _crypt function from authuser.php, which is required for apr1 and sha1 hashes, and which passes all others to Unix crypt() */ $pwHash = _crypt($passwd, $cryptsalt); return $pwHash; } /* CreateSalt: generates alphanumeric salt of given length */ function CreateSalt($max){ $i = 0; $salt = ""; $charList = "ABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyz0123456789"; while ($i <$max) { $salt = $salt . $charList{mt_rand(0, (strlen($charList) - 1))}; $i++; } return $salt; } ?>