-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMd5.cpp
More file actions
executable file
·60 lines (47 loc) · 1.43 KB
/
Md5.cpp
File metadata and controls
executable file
·60 lines (47 loc) · 1.43 KB
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
#include "Md5.h"
#include <QMessageBox>
#include <unistd.h>
#include <crypt.h>
IHashing *Md5::Create()
{
return new Md5();
}
void Md5::Free()
{
delete this;
}
/* Hashing */
char *Md5::encryptpass( QString passwd) const
{
HashEncode *hEnc = new HashEncode();
static char seed[12];
seed[0] = '$';
seed[1] = '1';
seed[2] = '$';
/*
* it produces different sets with pseudorandom numbers everytime the programm runs
* To continue, the srandom function returns random numbers in relation with the set of numbers being created from srandom
*/
srandom ( ( int ) time ( ( time_t * ) NULL ) );
hEnc->into64 ( &seed[3], random(),saltLength );
hEnc->into64 ( &seed[saltLength],random(),3 );
seed[saltLength+3] = '$';
if (hEnc != nullptr )
{delete hEnc;
hEnc = nullptr;}
char *buf = ( char * )calloc ( 512, sizeof(*buf) );
char *password = passwd.toLatin1().data();
memcpy ( buf,password,strlen(password));
/*
* The crypt_r function does the same thing as crypt,
* but takes an extra parameter which includes space for its result (among other things),
* so it can be reentrant. data->initialized must be cleared to zero before the first time crypt_r is called
*/
struct crypt_data data;
data.initialized = 0;
char *pass = crypt_r ( buf,seed, &data);
if ( pass == NULL )
QMessageBox::critical ( 0,QObject::tr ( "User Manager" ),QObject::tr ( "%1" ).arg ( ENOSYS ) );
if (buf!=NULL)free(buf);
return strdup ( pass );
}