Last active
December 18, 2020 18:02
-
-
Save Sasszem/72cd26342519f2562d88e3892c64877b to your computer and use it in GitHub Desktop.
OTP passwords! You can't hack it!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <time.h> | |
#include <stdlib.h> | |
#include <string.h> | |
/* | |
########## | |
# SOLVES # | |
########## | |
- sparrow | |
- KosmX | |
*/ | |
void genRandomPass(char* target, int count) { | |
srand(time(NULL)); // it's kinda secure | |
// you can side-channel it by running the generation at the exact same time, | |
// but that's not the intended way. | |
// Only reason I'm not using a better way is because I want to keep the code clean, and this is the simplest | |
for (int i = 0; i<count;i++) | |
target[i] = 'a' + rand()%26 + ('A'-'a')*(rand()%2); | |
} | |
int main() { | |
struct {char name[32], passWord[8+1];} strings = {{0},{0}}; | |
genRandomPass(strings.passWord, 8); | |
printf("Hello! Please pick a nickname:\n$ "); | |
char buffer[64]; | |
scanf("%64s", buffer); | |
strncpy(strings.name, buffer, 32); | |
printf("Hello, %s!\n", strings.name); | |
printf("Please input the password:\n$ "); | |
scanf("%8s", strings.name); | |
if (strncmp(strings.name, strings.passWord, 8)==0) | |
printf("Permission granted!\n"); | |
else | |
printf("Access denied!\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment