-2

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.

copycode
  • 21
  • 1
  • 4

2 Answers2

3

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
  • 83
  • 7
-1

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
  • 7,122
  • 8
  • 34
  • 59
  • 5
    should be mentioned here, that (at least in Python 3), this function does not guarantee to generate same values across processes (i.e. running `python -c "print(hash('abcde'))"` in terminal repeatedly, outputs different numbers) – peetonn Apr 04 '23 at 23:02