library/src/utility/BP-StringUtilities.cc
// Returns true if the salted password matches the plaintext provided
Returns true if the salted password matches the plaintext provided
Returns true if the salted password matches the plaintext provided
BP_BOOL BP_PasswordMatchesSaltedPlaintext(char *plaintext_password, char *hash_algo, char *hash, char *salt)
{
	if(!plaintext_password)
		return BP_FALSE;
	if(!hash_algo)
		return BP_FALSE;
	if(!hash)
		return BP_FALSE;
	if(!salt)
		return BP_FALSE;
	if(!BP_StringIsReasonablePrintableString(plaintext_password, bpstrlen(plaintext_password), BP_FALSE, BP_FALSE))
		return BP_FALSE;
	if(!BP_StringIsReasonablePrintableString(hash_algo, bpstrlen(hash_algo), BP_FALSE, BP_FALSE))
		return BP_FALSE;
	if(!BP_StringIsReasonablePrintableString(hash,      bpstrlen(hash),      BP_FALSE, BP_FALSE))
		return BP_FALSE;
	if(!BP_StringIsReasonablePrintableString(salt,      bpstrlen(salt),      BP_FALSE, BP_FALSE))
		return BP_FALSE;
	char * combined_plaintext_and_salt = BP_JoinStrings(salt, plaintext_password, NULL);
	if(!combined_plaintext_and_salt)
		return BP_FALSE;
	char *hashed_value = NULL;
	if(BP_StringsMatchAsReasonableStrings(hash_algo, "sha1"))
	{
		hashed_value = BP_GenSHA1(combined_plaintext_and_salt, bpstrlen(combined_plaintext_and_salt));
	}
	else if(BP_StringsMatchAsReasonableStrings(hash_algo, "sha256"))
	{
		hashed_value = BP_GenSHA256(combined_plaintext_and_salt, bpstrlen(combined_plaintext_and_salt));
	}
	else
	{
		memset(combined_plaintext_and_salt, 0x00, bpstrlen(combined_plaintext_and_salt));
		bpfree(combined_plaintext_and_salt);
		bpfree(hashed_value);
		return BP_FALSE;
	}
	printf("\n HASHED VALUE: %s", hashed_value);
	printf("\n HASH: %s", hash);
	printf("\n PASSCOMBINED: %s", combined_plaintext_and_salt);
	if(BP_StringsMatchAsReasonableStrings(hashed_value, hash))
	{
		memset(combined_plaintext_and_salt, 0x00, bpstrlen(combined_plaintext_and_salt));
		bpfree(combined_plaintext_and_salt);
		bpfree(hashed_value);
		return BP_TRUE;
	}
	memset(combined_plaintext_and_salt, 0x00, bpstrlen(combined_plaintext_and_salt));
	bpfree(combined_plaintext_and_salt);
	bpfree(hashed_value);
	return BP_FALSE;
}
BP_BOOL BP_PasswordMatchesSaltedPlaintext ( char * plaintext_password , char * hash_algo , char * hash , char * salt ) { if ( ! plaintext_password ) return BP_FALSE ; if ( ! hash_algo ) return BP_FALSE ; if ( ! hash ) return BP_FALSE ; if ( ! salt ) return BP_FALSE ; if ( ! BP_StringIsReasonablePrintableString ( plaintext_password , bpstrlen ( plaintext_password ) , BP_FALSE , BP_FALSE ) ) return BP_FALSE ; if ( ! BP_StringIsReasonablePrintableString ( hash_algo , bpstrlen ( hash_algo ) , BP_FALSE , BP_FALSE ) ) return BP_FALSE ; if ( ! BP_StringIsReasonablePrintableString ( hash , bpstrlen ( hash ) , BP_FALSE , BP_FALSE ) ) return BP_FALSE ; if ( ! BP_StringIsReasonablePrintableString ( salt , bpstrlen ( salt ) , BP_FALSE , BP_FALSE ) ) return BP_FALSE ; char * combined_plaintext_and_salt = BP_JoinStrings ( salt , plaintext_password , NULL ) ; if ( ! combined_plaintext_and_salt ) return BP_FALSE ; char * hashed_value = NULL ; if ( BP_StringsMatchAsReasonableStrings ( hash_algo , " " ) ) { hashed_value = BP_GenSHA1 ( combined_plaintext_and_salt , bpstrlen ( combined_plaintext_and_salt ) ) ; } else if ( BP_StringsMatchAsReasonableStrings ( hash_algo , " " ) ) { hashed_value = BP_GenSHA256 ( combined_plaintext_and_salt , bpstrlen ( combined_plaintext_and_salt ) ) ; } else { memset ( combined_plaintext_and_salt , 0x00 , bpstrlen ( combined_plaintext_and_salt ) ) ; bpfree ( combined_plaintext_and_salt ) ; bpfree ( hashed_value ) ; return BP_FALSE ; } printf ( " \n " , hashed_value ) ; printf ( " \n " , hash ) ; printf ( " \n " , combined_plaintext_and_salt ) ; if ( BP_StringsMatchAsReasonableStrings ( hashed_value , hash ) ) { memset ( combined_plaintext_and_salt , 0x00 , bpstrlen ( combined_plaintext_and_salt ) ) ; bpfree ( combined_plaintext_and_salt ) ; bpfree ( hashed_value ) ; return BP_TRUE ; } memset ( combined_plaintext_and_salt , 0x00 , bpstrlen ( combined_plaintext_and_salt ) ) ; bpfree ( combined_plaintext_and_salt ) ; bpfree ( hashed_value ) ; return BP_FALSE ; }
Returns true if the salted password matches the plaintext provided
Returns true if the salted password matches the plaintext provided
// ensure all parts are non-null // run reasonable string checks on all parts // set combined plaintext and salt // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Create Hash %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // hashed value // create hashes based on the hash algorithm // zero out the plaintext/salt // destroy the combined plaintext and salt // return indicating that a match was made // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Check Hash %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // zero out the plaintext/salt // destroy the combined plaintext and salt // return indicating that a match was made // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Cleanup %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // zero out the plaintext/salt // destroy the combined plaintext and salt // return indicating no match