def postgres_passwd(password, username, uppercase=False): """ Reference(s): http://pentestmonkey.net/blog/cracking-postgres-hashes/ >>> postgres_passwd(password='testpass', username='testuser', uppercase=False) 'md599e5ea7a6f7c3269995cba3927fd0093' """ if isinstance(username, unicode): username = unicode.encode(username, UNICODE_ENCODING) if isinstance(password, unicode): password = unicode.encode(password, UNICODE_ENCODING) retVal = "md5%s" % md5(password + username).hexdigest() return retVal.upper() if uppercase else retVal.lower()