-2

I want to hash my password many times but it's hard to repeat codes many times depends on exponent.

So, for example in this code for exponent 2 and base 3:

3**2= 9

So I need to hash my password nine times!

I scanned all the web to find any code for help in Python but all found in C language.

Is there an easy way to hash my password many times in Python with hashlib.sha356 not pbkdf2_hmac?

Here is code for example:

Hello World!

Result:

c079473ced8ca65d5ce59cabf451ab7a513db97ab4d2266b9cb0c4d13383fb81

from hashlib import sha256

pw = input('Enter Password: ')
h1 = sha256(pw.encode('utf-8')).digest()
h2 = sha256(h1).digest()
h3 = sha256(h2).digest()
h4 = sha256(h3).digest()
h5 = sha256(h4).digest()
h6 = sha256(h5).digest()
h7 = sha256(h6).digest()
h8 = sha256(h7).digest()
h9 = sha256(h8).hexdigest()
print(h9)
tony
  • 1
  • 2

1 Answers1

2
from hashlib import sha256

pw = input('Enter Password: ')
h = sha256(pw.encode('utf-8')).digest()

N = 10
for i in range(N):
    if i != N-1:
        h = sha256(h).digest()
    else:
        h = sha256(h).hexdigest()

print(h)
felipe
  • 7,324
  • 2
  • 28
  • 37