Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int decodeUserPass(char *authorization) {
- // Ausgabe der Logindaten
- if (authorization != NULL) {
- char *auth64 = authorization;
- char *authDecode = (char *) calloc(sizeof(char), BUFFERSMALL);
- char *clear_user = (char *) calloc(sizeof(char), BUFFERSMALL);
- char *clear_password = (char *) calloc(sizeof(char), BUFFERSMALL);
- char *sha1_password_base64 = (char *) calloc(sizeof(char), BUFFERSMALL);
- char *sha1_password = (char *) calloc(sizeof(char), BUFFERSMALL);
- int i = 0;
- // Ausgabe base64 codierter auth-string
- //printf("%s\n",auth64);
- // Ausgabe dekodierter auth-string
- Base64decode(authDecode, auth64);
- //printf("%s\n",authDecode);
- // Suche Stelle des Doppelpunkts
- while (strncmp(authDecode + i, ":", 1) != 0) {
- i++;
- }
- // Benutzernamen ausgeben
- strncpy(clear_user, authDecode, (size_t) i);
- printf("Benutzer: %s\n", clear_user);
- // Passwort ausgeben
- strcpy(clear_password, authDecode + i + 1);
- printf("Passwort: %s\n\n", clear_password);
- // SHA1 von password ausgeben
- makeSha1(clear_password, sha1_password);
- printf("SHA1: %s\n", sha1_password);
- // Base64 SH1 von password ausgeben
- Base64encode(sha1_password_base64, sha1_password, (int) strlen(sha1_password));
- printf("SHA1_Base64: %s\n\n", sha1_password_base64);
- int status = checkUserPass(clear_user, sha1_password_base64);
- free(clear_password);
- free(clear_user);
- free(sha1_password_base64);
- free(sha1_password);
- free(authDecode);
- return status;
- }
- return 0;
- }
- int checkUserPass(char *user, char *base64) {
- char *pathbuffer = (char *) calloc(sizeof(char), BUFFERSMALL);
- strcpy(pathbuffer, getRoot());
- strcat(pathbuffer, (const char *) "/htpasswd");
- char *file;
- file = loadFile(pathbuffer);
- free(pathbuffer);
- if (file == NULL){
- return 0;
- }
- char *userpass = (char *) calloc(sizeof(char), BUFFERSMALL);
- strPaste(userpass, user, BUFFERSMALL);
- strPaste(userpass, ":{SHA}", BUFFERSMALL);
- strPaste(userpass, base64, BUFFERSMALL);
- if (strstr(file, userpass)) {
- free(userpass);
- free(file);
- return 1;
- }
- free(userpass);
- free(file);
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement