Created
          February 25, 2012 23:37 
        
      - 
      
- 
        Save meeDamian/1911687 to your computer and use it in GitHub Desktop. 
    [ PHP | lib ] quite a hash function
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <? | |
| // put this to libs file | |
| function make_hash( $pass, $salt, $email, $linear=false ) { | |
| $numb = ""; | |
| foreach( str_split($salt) as $char ) if( is_numeric( $char )) $numb .= $char; | |
| mt_srand( (int)$numb ); | |
| $algs = array('whirlpool', 'sha512', 'sha384', 'ripemd320', 'snefru256', 'gost', 'snefru', 'ripemd256', 'sha256', 'sha224'); | |
| // check if all algorithms are available | |
| foreach($algs as $hash) if(!in_array($hash,hash_algos())) throw new Exception("Unsupported algorithms."); | |
| $hash = $pass; | |
| foreach( str_split($salt) as $i => $char ) { | |
| $str = $hash . $char; | |
| if( $i%3 == 0 ) $str .= $email; | |
| if( $i%7 == 0 ) $str .= mt_rand( $hash ); | |
| $hash = ( $linear ) ? | |
| hash( $algs[ $i%count($algs) ], $str, false ) : | |
| make_hash( $hash, $salt, $email, true ); | |
| } | |
| return ( $linear ) ? $hash : sha1($hash); | |
| } | |
| // usage: | |
| $hash = make_hash("userFunnyPassword","randomlyGeneratedAndSavedSalt_TheLongerTheBetter","[email protected]"); | |
| ?> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment