Suppose I wish to store passwords in my code. Is SHA256 a good enough way to store them?
Here's what the code looks like:
#!/usr/bin/python3
#The password is 'helloWorld'
import hashlib
hashedString = "11d4ddc357e0822968dbfd226b6e1c2aac018d076a54da4f65e1dc8180684ac3"
for i in range(3):
x = input('Password: ') # For now, ignore the fact that it's exposed.
if hashlib.sha256(x.encode()).hexdigest() == hashedString:
print('Access granted!')
exit()
else:
print('Wrong password.')
print('3 attempts!')
Now, there are problems with this, such as the possibility that there are other strings with the same SHA256 hash.
So is there another way to store them (without giving explicit information such as password length, etc.)?