The problem is that in Python hash()
it is NOT a cryptographic routine, it is simply an internal routine to return an integer value that functions as the unique identifier of the object. The same password in different executions or instances of Pyhton will give you multiple hash
. for example:
c:> python -c "print(hash('hola'))"
c:> 161768099
c:> python -c "print(hash('hola'))"
c:> -339335518
What you can do is use the module hashlib
in the following way:
import hashlib
hash = hashlib.sha256("contraseña").hexdigest()
print(hash)
> edf9cf90718610ee7de53c0dcc250739239044de9ba115bb0ca6026c3e4958a5
The received string will be your hash
to save in the database. In PHP if the routine hash()
exists as cryptographic, the way to repeat the previous code would be like this:
<?php
echo hash('sha256', 'contraseña');
?>
edf9cf90718610ee7de53c0dcc250739239044de9ba115bb0ca6026c3e4958a5
Important:
The choice of the hash algorithm is a whole issue, md5
is extremely easy and fast to calculate, so brute force attacks are totally feasible, I suggest you point to sha256
up, generate hashes
longer and more difficult to solve by brute force. In any case these algorithms are of general purpose and were not specially designed to resolve passwords, if we add that the computational power continues to grow, a hash
considered safe today can not be tomorrow. Today, other algorithms are often recommended to treat passwords, I recommend this document .