Guest User

Untitled

a guest
Jan 29th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void fill_password(char* password) {
  6.         //imagine this is imported from a database or something
  7.         strncpy(password, "thisisthepassword", 32);
  8.         return;
  9. }
  10.  
  11. int main() {
  12.         char* username = (char*)malloc(32);
  13.         char* password = (char*)malloc(32);
  14.         char* given_pass = (char*)malloc(32);
  15.         fill_password(password);
  16.         printf("Enter your username: ");
  17.         gets(username);
  18.         printf("Greetings %s, please enter your password: ", username);
  19.         gets(given_pass);
  20.         if (strncmp(given_pass, password, 32) == 0) {
  21.                 printf("Yay, you logged in!\n");
  22.         }
  23.         else {
  24.                 printf("Sorry, incorrect password\n");
  25.         }
  26.         return 0;
  27. }
Add Comment
Please, Sign In to add comment