E
E
Evgeny_A2020-10-23 09:31:38
Python
Evgeny_A, 2020-10-23 09:31:38

How to unambiguously determine that a string is hashed?

Greetings.

Moved URL hashing into a separate function to search for matches in the database. I want to handle the situation when the input of this function is not the original URL, but an already hashed string, so that the function does not hash it again by accident.

Checking for the presence of a protocol (https or http) or a zone (.com, .ru) in a string does not seem like a good idea to me, because it is impossible to describe all possible URL options (for example, relative paths will not work at all).

If you try to parse the hash from the URL using urllib.parse.urlparse, the result is:

ParseResult(scheme='', netloc='', path='d8058d63868cb6d89211e6ec5a12ccf8', params='', query='', fragment='')


Share how you would solve such a problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny_A, 2020-10-23
@Evgeny_A

Everything turned out to be simple. It was necessary not to check for hashing, but for the fact that the URL is valid. The fastest solution:

import validators
validators.url("http://google.com")

D
Dr. Bacon, 2020-10-23
@bacon

Fixed length and characters only 0-9 and af

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question