Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @hacky02:~$ cat /Uebungen/Aufgabenblatt01/Aufgabe02/auth.c
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- char *salt = "$6$aGzikL66hsj/hs$";
- int auth(char *username, char *password)
- {
- int result = 0;
- char pw_user[20];
- char * pw_hash;
- // Prepare pw
- strcpy(pw_user, password);
- strcat(pw_user, username);
- // Get Hash
- printf("\n\nUser: %s\n", username);
- printf("Password: %s\n", password);
- pw_hash = crypt(pw_user, salt);
- printf("Password Hash: %s\n", pw_hash);
- if(strcmp(username, "00") == 0 &&
- strcmp(pw_hash, "$6$aGzikL66hsj/hs$1KUTqGk7PDos.KzfFdMEjakeURJ5GzB.HtgVnKXDAEQZju2td0RSp0l0hLtMKWMpUpyF.V/JwZg79Nv5mZmQx/") == 0)
- {
- result = 1;
- }
- return result;
- }
- void printUsage()
- {
- printf("Usage: auth <username> <password>\n");
- exit(-1);
- }
- int main(int argc, char *argv[])
- {
- if(argc < 3)
- printUsage();
- if(auth(argv[1], argv[2]) == 1)
- {
- printf("\n\n#####################################################\n");
- printf("# #\n");
- printf("# !ACCESS GRANTED! #\n");
- printf("# #\n");
- printf("#####################################################\n\n\n");
- printf("Welcome %s!\n", argv[1]);
- }
- else
- {
- printf("\n\n#####################################################\n");
- printf("# #\n");
- printf("# !ACCESS DENIED! #\n");
- printf("# #\n");
- printf("#####################################################\n\n\n");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment