Skip to content

Instantly share code, notes, and snippets.

@Sasszem
Last active December 18, 2020 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sasszem/72cd26342519f2562d88e3892c64877b to your computer and use it in GitHub Desktop.
Save Sasszem/72cd26342519f2562d88e3892c64877b to your computer and use it in GitHub Desktop.
OTP passwords! You can't hack it!
#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