1
votes

I'm following some python book and the author provides an example of using crypt to produce a hashed password. Using the salt+password; and later he mentioned that the same could be done for sha512 using hashlib library. So I tried to use hashlib.sha512(password+salt).hexdigest() to see if I could come up with my same password in the /etc/shadow file, but I'm not getting anything remotely similar. I'm using the salt that shows as part of my password hash. Am I doing it correctly, or that salt needs to be in ascii form? Also does the salt goes first and then the password like hashlib.sha512(salt+password).hexdigest()? the rest of my code is pretty simple. It is that part about finding the salt, and hashing it properly. nagios:$6$P9zn0KwR$tgfvvFWJJ5FKmoXiP5rXWOjwoEBOEoAuBi3EphRbJqqjWYvhEM2wa67L9XgQ7W591FxUNklkDIQsk4kij uhE50:16632:0:99999:7:::

for example the salt I'm using is "P9zn0KwR" is this correct or I need to find the clear text for that salt... thanks

1

1 Answers

1
votes

Using hash algorithms like MD5 or SHA-* is an unsecure way to store passwords, because they are ways too fast and therefore can be brute-forced too easily.

Have a look at the Phyton docs, the part about key stretching. It seems that they implemented the PBKDF2 for passwords which is recommended. The passlib seems to be a good choice too, they support the BCrypt algorithm.