summaryrefslogtreecommitdiff
path: root/CmdLineAuth.c
blob: 24b93e80362ab322c11c3c264e18afd6e3beb7a6 (plain)
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
// CmdLineAuth.cpp : Defines the entry point for the console application.
//

#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
#define _CRT_SECURE_NO_DEPRECATE 

#define _USE_32BIT_TIME_T

#include <stdio.h>

#include <time.h>
#include <stdio.h>

#include "md5.c"


VOID CreateOneTimePassword(char * KeyPhrase)
{
	// Create a time dependent One Time Password from the KeyPhrase

	time_t NOW = time(NULL);
	unsigned char Hash[16];
	char Password[20];
	char Key[1000];
	int i, chr;
	long long Val;
	int PassCode;

	NOW = NOW/30;							// Only Change every 30 secs

	sprintf(Key, "%s%x", KeyPhrase, NOW);

	md5(Key, Hash);

	for (i=0; i<16; i++)
	{
		chr = (Hash[i] & 31);
		if (chr > 9) chr += 7;
		
		Password[i] = chr + 48; 
	}

	Password[16] = 0;

	memcpy(&Val, Password, 8);
	PassCode = Val % 1000000;
	printf("Passcode is %06d\n", PassCode);

	return;
}

int main(int argc, char * argv[])
{
	if (argc < 2)
	{
		printf ("Need to supply KeyPhrase\n");
		return 0;
	}
	CreateOneTimePassword(argv[1]);
	return 0;
}