Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void fill_password(char* password) {
- //imagine this is imported from a database or something
- strncpy(password, "thisisthepassword", 32);
- return;
- }
- int main() {
- char* username = (char*)malloc(32);
- char* password = (char*)malloc(32);
- char* given_pass = (char*)malloc(32);
- fill_password(password);
- printf("Enter your username: ");
- gets(username);
- printf("Greetings %s, please enter your password: ", username);
- gets(given_pass);
- if (strncmp(given_pass, password, 32) == 0) {
- printf("Yay, you logged in!\n");
- }
- else {
- printf("Sorry, incorrect password\n");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment