-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (54 loc) · 1.56 KB
/
main.cpp
File metadata and controls
63 lines (54 loc) · 1.56 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
57
58
59
60
61
62
/*
* File: main.c
* Author: dbento
*
* Created on June 8, 2010, 7:14 PM
*/
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include "hotp.h"
#include "hotputil.h"
#include "hmacsha1.h"
#include "mwintype.h"
#include "registry.h"
static char valid_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-+=@";
static int valid_chars_num = 67;
/*
*
*/
int main(int argc, char** argv) {
unsigned char horatexto[8];
time_t hora = time(NULL);
hora = hora / 60;
c2c(hora,horatexto);
int newSecret = 1; /* FALSE */
HKEY chave = OpenCreateKey("Software\\bento.eti.br\\Token");
if(chave != NULL) {
char valor[21];
memset((void *)valor,'\0', 21);
DWORD tam = 21;
if(!ReadKeyValue(chave, "Segredo", valor, &tam)) {
srand(time(NULL));
for(int i = 0; i < 20; i++) {
valor[i] = valid_chars[rand() % 67];
}
tam = 20;
if(!WriteKeyValue(chave, "Segredo", valor))
return(EXIT_FAILURE);
else {
std::cout << "Segredo: " << valor << std::endl;
newSecret = 0; /* TRUE */
}
}
CloseKey(chave);
if(newSecret) {
BYTE digest[CHMAC_SHA1::SHA1_DIGEST_LENGTH];
std::cout << test_hotp((BYTE *)horatexto, (BYTE *)valor, (BYTE *)digest, 6) << std::endl;
//MessageBox(NULL, (char *)test_hotp((BYTE *)horatexto, (BYTE *)valor, (BYTE *)digest, 6), (char *)"Senha", MB_OK+MB_APPLMODAL+MB_ICONINFORMATION);
}
return(EXIT_SUCCESS);
}
return(EXIT_FAILURE);
}