summaryrefslogtreecommitdiff
path: root/CmdLineAuth.c
diff options
context:
space:
mode:
authorJohn Wiseman <john.wiseman@cantab.net>2022-08-28 09:35:46 +0100
committerJohn Wiseman <john.wiseman@cantab.net>2022-08-28 09:35:46 +0100
commite3ea58d23aae3aca6f382c4b95ec31a1f7875cae (patch)
tree6aa82a196df5ce3330d112e047febc348c44dc1d /CmdLineAuth.c
Diffstat (limited to 'CmdLineAuth.c')
-rw-r--r--CmdLineAuth.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/CmdLineAuth.c b/CmdLineAuth.c
new file mode 100644
index 0000000..24b93e8
--- /dev/null
+++ b/CmdLineAuth.c
@@ -0,0 +1,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;
+}
+