View difference between Paste ID: 20gVc2a4 and mjfz17R5
SHOW: | | - or go back to the newest paste.
1
/*
2
3-
	wphashsalted.inc
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-
// stock WhirlpoolHashUnique(string[], salt[], times)
26+
27
	R1
28
	- Initial release.
29
*/
30-
stock WhirlpoolHashUnique(string[], salt[], times)
30+
31
#if !defined WP_Hash
32-
	new stringTaken[129];
32+
33
#endif
34-
	strcat(stringTaken, string);
34+
35-
	strcat(stringTaken, salt);
35+
// stock WhirlpoolHashUnique(string[], salt[], times, bool: iter_append = false)
36
// string[] - Takes the string you would like to hash.
37-
	for(new i = 0; i < times; i++)
37+
38-
		WP_Hash(stringTaken, 129, stringTaken);	
38+
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-
// stock WhirlpoolHashRandom(string[], salt[], times)
42+
	new stringTaken[258];
43
	
44
	if(!iter_append) 
45
	{		
46
		strcat(stringTaken, string, 258);
47-
stock WhirlpoolHashRandom(string[], times, salt[], salt_length)
47+
		strcat(stringTaken, salt, 258);
48
		
49-
	new stringTaken[129];
49+
		for(new i = 0; i < times; i++) 		
50
			WP_Hash(stringTaken, 258, stringTaken);			
51
	}
52
	else
53
	{		
54
		strcat(stringTaken, string);
55-
	}		
55+
56
		for(new i = 0; i < times; i++) 
57-
	randomString(salt, salt_length);
57+
		{
58-
	strcat(stringTaken, string);	
58+
			strcat(stringTaken, salt);
59-
	strcat(stringTaken, salt);	
59+
			WP_Hash(stringTaken, 258, stringTaken);
60
		}
61-
	for(new i = 0; i < times; i++)
61+
	}
62-
		WP_Hash(stringTaken, 129, stringTaken);
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
}