SHARE
TWEET

Untitled

a guest Jul 21st, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _XOPEN_SOURCE
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <strings.h>
  6. #include <unistd.h>
  7.  
  8. #include <sys/types.h>
  9. #include <pwd.h>
  10.  
  11. #define BUFFSIZE 1024
  12.  
  13. void strip(char *inptstri)
  14. {
  15.     int tempsize;
  16.    
  17.     tempsize = strlen(inptstri);
  18.    
  19.     if (tempsize > 0)
  20.     {
  21.         inptstri[tempsize - 1] = '\0';
  22.     }
  23. }
  24.  
  25. int main(int argc, char **argv)
  26. {
  27.     char username[BUFFSIZE], password[BUFFSIZE], datetime[BUFFSIZE];
  28.     char *cryppass;
  29.     struct passwd *passdata;
  30.    
  31.     printf("Username: ");
  32.     bzero(username, BUFFSIZE * sizeof(char));
  33.     fgets(username, BUFFSIZE - 1, stdin);
  34.     strip(username);
  35.    
  36.     printf("Password: ");
  37.     bzero(password, BUFFSIZE * sizeof(char));
  38.     fgets(password, BUFFSIZE - 1, stdin);
  39.     strip(password);
  40.    
  41.     if ((passdata = getpwnam(username)) == NULL)
  42.     {
  43.         return 1;
  44.     }
  45.    
  46.     cryppass = crypt(password, passdata->pw_passwd);
  47.    
  48.     if (strcmp(cryppass, passdata->pw_passwd) != 0)
  49.     {
  50.         printf("Invalid login!\n");
  51.         return 2;
  52.     }
  53.    
  54.     printf("Set time [hh:mm]: ");
  55.     bzero(datetime, BUFFSIZE * sizeof(char));
  56.     fgets(datetime, BUFFSIZE - 1, stdin);
  57.     strip(datetime);
  58.    
  59.    
  60.    
  61.     return 0;
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top