Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- final class sec
- {
- public function hash($string, $salt1='', $salt2='', $hash='')
- {
- if(empty($salt1))
- {
- $h = $this->randHash();
- $s = array(
- $this->randSalt(),
- $this->randSalt()
- );
- $string = $s[0] . wordwrap($string, strlen($string) / 2, $s[1]) . $s[0];
- $string = hash($h, $string);
- return array(
- 'string' => $string,
- 'salt1' => $s[0],
- 'salt2' => $s[1],
- 'hash' => $h
- );
- }
- else
- {
- $string = $salt1 . wordwrap($string, strlen($string) / 2, $salt2) . $salt1;
- return ( string ) hash($hash, $string);
- }
- }
- private function randHash()
- {
- $h = hash_algos();
- return $h[array_rand($h)];
- }
- private function randSalt()
- {
- $l = array_merge(
- range('a', 'z'),
- range('A', 'Z'),
- range(0, 9),
- array('!', '"', '�', '$', '%', '^', '&', '*', '(', ')', '[', ']', ':', '{', '}', '~', '#', '|', '\', '@', ';', '.', ',', '<', '>', '/', '?', '+', '=', '_', '-')
- );
- $tmp = NULL;
- for($i = 0; $i <= mt_rand(5, 12); $i++)
- {
- $tmp .= $l[array_rand($l)];
- }
- return ( string ) $tmp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment