-
Notifications
You must be signed in to change notification settings - Fork 0
/
nbgenerator.c
54 lines (42 loc) · 1.6 KB
/
nbgenerator.c
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
#include "nbgenerator.h"
char password[MAX_PASSWORD_LENGTH] = {0};
int getPseudoNumber(int numLimit){
int rNumber = 0;
srand(time(NULL));
if(numLimit > 0)
rNumber = rand() % numLimit;
else
rNumber = rand() % DEFAULT_MAX_NUMBER_LIMIT;
return rNumber;
}
// generationMotDePasse : not exported to client binary
char *generationMotDePasse(int nbCharacters){
short i = 0;
memset(password, 0, MAX_PASSWORD_LENGTH);
srand(time(NULL));
if((nbCharacters > MAX_PASSWORD_LENGTH) || (nbCharacters <= 0))
nbCharacters = MAX_PASSWORD_LENGTH;
/* Génération du mot de passe */
for(i = 0; i< nbCharacters; i++){
password[i] = 'A' + (rand() % nbCharacters);
}
return password;
}
/* @ means use this for legacy (old binaries) */
__asm__(".symver getRandomPassword_1_1,getRandomPassword@NBGENERATOR_1.1");
char* getRandomPassword_1_1(int nbCharacters){
return generationMotDePasse(nbCharacters);
}
/* @@ means default use this for new binaries */
__asm__(".symver getRandomPassword_2_0,getRandomPassword@@NBGENERATOR_2.0");
struct PasswordHash getRandomPassword_2_0(int nbCharacters){
char passwordToHash[MAX_PASSWORD_LENGTH];
char passwordSalt[6];
strcpy(passwordToHash, generationMotDePasse(10));
// $1$ allows to select md5 hashing algorithm
sprintf(passwordSalt, "$6$%s", generationMotDePasse(6));
sprintf(passHash.hashNameFunc, "%s", ENCRYPTION_CIPHER_METHOD);
/* Crypt returns a hash based on DES encryption */
passHash.hashedPassword = crypt(passwordToHash, passwordSalt);
return passHash;
}