-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
samp_bcrypt.inc
111 lines (99 loc) · 2.37 KB
/
samp_bcrypt.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#if defined _inc_samp_bcrypt
#undef _inc_samp_bcrypt
#endif
#if defined _samp_bcrypt_included
#endinput
#endif
#define _samp_bcrypt_included
#if !defined BCRYPT_HASH_LENGTH
#define BCRYPT_HASH_LENGTH (60 + 1)
#endif
#if !defined BCRYPT_COST
#define BCRYPT_COST (12)
#endif
/*
bcrypt_hash(playerid, const callback[], const input[], cost, const args[] = "", {Float, _}:...)
Params
`playerid` - id of the player
`callback[]` - callback to execute after hashing
`input[]` - string to hash
`cost` - work factor (4 - 31)
`args[]` - custom arguments
Example
```
main()
{
bcrypt_hash(0, "OnPassswordHash", "text", BCRYPT_COST);
}
forward OnPassswordHash(playerid, hashid);
public OnPassswordHash(playerid, hashid)
{
// hashid is id of stored result in memory
}
```
*/
native bcrypt_hash(playerid, const callback[], const input[], cost, const args[] = "", {Float, _}:...);
/*
bcrypt_verify(playerid, const callback[], const input[], const hash[], const args[] = "", {Float, _}:...)
Params
`playerid` - id of the player
`callback[]` - callback to execute after hashing
`input[]` - text to compare with hash
`hash[]` - hash to compare with text
`args[]` - custom arguments
Example
```
main()
{
bcrypt_verify(0, "OnPassswordVerify", "text", "$2y$12$lSzxFYNULh7weMGb8tf0beY1Lkb429nF.umuO/n0O.Q3U6wb1h5x.");
}
forward OnPassswordVerify(playerid, bool:success);
public OnPassswordVerify(playerid, bool:success)
{
// success denotes verifying was successful or not
if (success)
{
// Verified
}
else
{
// Hash doesn't match with text
}
}
```
*/
native bcrypt_verify(playerid, const callback[], const input[], const hash[], const args[] = "", {Float, _}:...);
/*
bcrypt_get_hash(dest[], size = sizeof(hash))
Params
`dest[]` - string to store hashed data
`size` - max size of dest string
Example
```
main()
{
bcrypt_hash(0, "OnPassswordHash", "text", BCRYPT_COST);
}
forward OnPassswordHash(playerid, hashid);
public OnPassswordHash(playerid, hashid)
{
new dest[BCRYPT_HASH_LENGTH];
bcrypt_get_hash(dest);
printf("hash : %s", dest);
}
```
*/
native bcrypt_get_hash(hash[], size = sizeof(hash));
/*
bcrypt_set_thread_limit(value)
Params
`value` - number of worker threads at a time
Example
```
main()
{
bcrypt_set_thread_limit(3);
}
```
*/
native bcrypt_set_thread_limit(value);