I simply want to hash a string (a Password) in Python 3. How do I do that? What is a Simple Way of doing that? Could you please give a Coding example or Recommend me a Module that can use.
Asked
Active
Viewed 196 times
2 Answers
0
You can hash values in Python 3 with Hashlib:
import hashlib
h = hashlib.new('sha256')#sha256 can be replaced with diffrent algorithms
h.update('Hello World'.encode()) #give a encoded string. Makes the String to the Hash
print(h.hexdigest())#Prints the Hash
urwolfiii
- 53
- 6
-
2
-
-
-
@copycode You can see all Algorithms usable by printing out `hashlib.algorithms_available()` but I recommend sicking to sha256 because some algorithms are old/outdated. – urwolfiii Dec 27 '21 at 17:21
0
I don't think there can be an easier way than using the built-in keyword hash:
In [1]: hash("Hello, world!")
Out[1]: 7195831199436619873
user1717828
- 6,812
- 6
- 31
- 52