Browse Source

Good advice

Piotr Czajkowski 4 years ago
parent
commit
4aea747700
2 changed files with 3 additions and 34 deletions
  1. 2 33
      pwned.c
  2. 1 1
      sha.c

+ 2 - 33
pwned.c

@@ -5,10 +5,7 @@
 // https://haveibeenpwned.com/API/v2#SearchingPwnedPasswordsByRange
 
 #define HASH_PREFIX_LENGTH 5
-#define HASH_PREFIX_SIZE 6
-
 #define HASH_SUFFIX_LENGTH 35
-#define HASH_SUFFIX_SIZE 36
 
 #define URL_SIZE 43
 #define BASEURL_SIZE 38
@@ -24,26 +21,6 @@ char *getURL(const char* hash) {
 	return url;
 }
 
-char *getSuffixUppercase(const char *hash) {
-	char hashSuffix[HASH_SUFFIX_SIZE];
-	strcpy(hashSuffix, hash+HASH_PREFIX_LENGTH);
-
-	char *suffixUpper = malloc(HASH_SUFFIX_SIZE);
-	if (suffixUpper == NULL) {
-		puts("Couldn't allocate memory for suffix!");
-		return NULL;
-	}
-
-	for (int i = 0; i < HASH_SUFFIX_LENGTH; i++) {
-		int c = hashSuffix[i];
-		c = toupper(c);
-		sprintf(suffixUpper+i, "%c", c);
-	}
-	suffixUpper[HASH_SUFFIX_LENGTH] = 0;
-
-	return suffixUpper;
-}
-
 int printNumber(char *text) {
 	char *part = strchr(text, ':');
 	if (part == NULL) return 0;
@@ -93,14 +70,6 @@ int main(int argc, char **argv) {
 		return 1;
 	}
 
-	char *suffix = getSuffixUppercase(hash);
-	if (suffix == NULL) {
-		puts("Couldn't make suffix uppercase!");
-		return 1;
-	}
-
-	free(hash);
-
 	char *data = getData(url);
 	if (data == NULL) {
 		puts("Couldn't get data from the API!");
@@ -109,8 +78,8 @@ int main(int argc, char **argv) {
 
 	free(url);
 
-	if (!findSuffix(suffix, data)) puts("Password not pwned!");
+	if (!findSuffix(hash+HASH_PREFIX_LENGTH, data)) puts("Password not pwned!");
 
+	free(hash);
 	free(data);
-	free(suffix);
 }

+ 1 - 1
sha.c

@@ -20,7 +20,7 @@ static char *hashToString(unsigned char *hash) {
 	}
 
 	for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
-		sprintf(string+(i*2), "%02x", hash[i]);
+		sprintf(string+(i*2), "%02X", hash[i]);
 
 	return string;
 }