Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- wphashsalted.inc - r2
- "Two easy to use functions that allow you to hash strings as fast as possible."
- Copyright 2013 Giampaolo Falqui
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- Changelog:
- R2
- - Modified parameters order of WhirlpoolHashRandom.
- - 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.
- - Fixed minor internal documentation mistakes.
- R1
- - Initial release.
- */
- #if !defined WP_Hash
- native WP_Hash(buffer[], len, const str[]);
- #endif
- // stock WhirlpoolHashUnique(string[], salt[], times, bool: iter_append = false)
- // string[] - Takes the string you would like to hash.
- // salt[] - Takes a unique salt that will be concatenated with the string and hashed together.
- // times - How many times does the function have to hash the string before returning the value.
- // 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.
- stock WhirlpoolHashUnique(string[], times, salt[], bool: iter_append = false)
- {
- new stringTaken[258];
- if(!iter_append)
- {
- strcat(stringTaken, string, 258);
- strcat(stringTaken, salt, 258);
- for(new i = 0; i < times; i++)
- WP_Hash(stringTaken, 258, stringTaken);
- }
- else
- {
- strcat(stringTaken, string);
- for(new i = 0; i < times; i++)
- {
- strcat(stringTaken, salt);
- WP_Hash(stringTaken, 258, stringTaken);
- }
- }
- return stringTaken;
- }
- // stock WhirlpoolHashRandom(string[], salt[], times, salt_length, bool: iter_append = false)
- // string[] - Takes the string you would like to hash.
- // times - How many times does the function have to hash the string before returning the value.
- // salt[] - Reference string that contains the salt returned by randomString();
- // salt_length - How many characters will contain the salt.
- // 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.
- stock WhirlpoolHashRandom(string[], times, salt[], salt_length, bool: iter_append = false)
- {
- new stringTaken[258];
- if(salt_length < 1)
- {
- strcat(stringTaken, "NULL");
- return stringTaken;
- }
- if(!iter_append)
- {
- randomString(salt, salt_length);
- strcat(stringTaken, string, 258);
- strcat(stringTaken, salt, 258);
- for(new i = 0; i < times; i++)
- WP_Hash(stringTaken, 258, stringTaken);
- }
- else
- {
- randomString(salt, salt_length);
- strcat(stringTaken, string, 258);
- for(new i = 0; i < times; i++)
- {
- strcat(stringTaken, salt, 258);
- WP_Hash(stringTaken, 258, stringTaken);
- }
- }
- return stringTaken;
- }
- stock randomString(strDest[], strLen = 10)
- {
- while(strLen--)
- strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement