Advertisement
GiamPy

wphashsalted.inc R2 | Easy to Use Hashing Functions

Jul 8th, 2013
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     wphashsalted.inc - r2
  4.     "Two easy to use functions that allow you to hash strings as fast as possible."
  5.  
  6.     Copyright 2013 Giampaolo Falqui
  7.  
  8.     Licensed under the Apache License, Version 2.0 (the "License");
  9.     you may not use this file except in compliance with the License.
  10.     You may obtain a copy of the License at
  11.  
  12.         http://www.apache.org/licenses/LICENSE-2.0
  13.  
  14.     Unless required by applicable law or agreed to in writing, software
  15.     distributed under the License is distributed on an "AS IS" BASIS,
  16.     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17.     See the License for the specific language governing permissions and
  18.     limitations under the License.
  19.    
  20.     Changelog:
  21.    
  22.     R2
  23.     - Modified parameters order of WhirlpoolHashRandom.
  24.     - Added the paramater iter_append to choose if appending the salt for every iteration. It slightly slows down the process but it increases the security.
  25.     - Fixed minor internal documentation mistakes.
  26.    
  27.     R1
  28.     - Initial release.
  29. */
  30.  
  31. #if !defined WP_Hash
  32. native WP_Hash(buffer[], len, const str[]);
  33. #endif
  34.  
  35. // stock WhirlpoolHashUnique(string[], salt[], times, bool: iter_append = false)
  36. // string[] - Takes the string you would like to hash.
  37. // salt[] - Takes a unique salt that will be concatenated with the string and hashed together.
  38. // times - How many times does the function have to hash the string before returning the value.
  39. // bool: iter_append - Choose if you'd like to append the salt for every iteration or not. It increase the security but it slightly slows down the process.
  40. stock WhirlpoolHashUnique(string[], times, salt[], bool: iter_append = false)
  41. {      
  42.     new stringTaken[258];
  43.    
  44.     if(!iter_append)
  45.     {      
  46.         strcat(stringTaken, string, 258);
  47.         strcat(stringTaken, salt, 258);
  48.        
  49.         for(new i = 0; i < times; i++)     
  50.             WP_Hash(stringTaken, 258, stringTaken);        
  51.     }
  52.     else
  53.     {      
  54.         strcat(stringTaken, string);
  55.        
  56.         for(new i = 0; i < times; i++)
  57.         {
  58.             strcat(stringTaken, salt);
  59.             WP_Hash(stringTaken, 258, stringTaken);
  60.         }
  61.     }
  62.    
  63.     return stringTaken;
  64. }
  65.    
  66. // stock WhirlpoolHashRandom(string[], salt[], times, salt_length, bool: iter_append = false)
  67. // string[] - Takes the string you would like to hash.
  68. // times - How many times does the function have to hash the string before returning the value.
  69. // salt[] - Reference string that contains the salt returned by randomString();
  70. // salt_length - How many characters will contain the salt.
  71. // bool: iter_append - Choose if you'd like to append the salt for every iteration or not. It increase the security but it slightly slows down the process.
  72. stock WhirlpoolHashRandom(string[], times, salt[], salt_length, bool: iter_append = false)
  73. {
  74.     new stringTaken[258];
  75.    
  76.     if(salt_length < 1)
  77.     {
  78.         strcat(stringTaken, "NULL");
  79.         return stringTaken;
  80.     }
  81.    
  82.     if(!iter_append)
  83.     {          
  84.         randomString(salt, salt_length);
  85.         strcat(stringTaken, string, 258);
  86.         strcat(stringTaken, salt, 258);        
  87.        
  88.         for(new i = 0; i < times; i++)     
  89.             WP_Hash(stringTaken, 258, stringTaken);
  90.     }
  91.     else
  92.     {                  
  93.         randomString(salt, salt_length);
  94.         strcat(stringTaken, string, 258);      
  95.        
  96.         for(new i = 0; i < times; i++)
  97.         {
  98.             strcat(stringTaken, salt, 258);
  99.             WP_Hash(stringTaken, 258, stringTaken);
  100.         }
  101.     }
  102.    
  103.     return stringTaken;
  104. }
  105.  
  106. stock randomString(strDest[], strLen = 10)
  107. {
  108.     while(strLen--)
  109.         strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement