Reputation: 33
So, I have this entry in a linux shadow file
google.:$1$8KdNUQ4R$ZYyUXVGhvLgVNpfqus.GX/::1:0:1:1:::
The password for this user is com
As I understand the $1$
means it is hashed using md5;
8KdNUQ4R
is the salt; and ZYyUXVGhvLgVNpfqus.GX/
is the hashed password itself.
What confuses me is that md5 generators I found online produce a hex value that is 32 characters long, but the hashed password in this case is only 22 chars long, and definitely not a hex.
What steps do I have to go through to get from com
to ZYyUXVGhvLgVNpfqus.GX/
using the given salt ?
Edit
So, I found my answer. My problem was that I should have used md5crypt instead of md5.
Upvotes: 3
Views: 2576
Reputation: 44238
If you need to calculate hash for particular password use crypt(3):
#include <iostream>
#include <unistd.h>
int main()
{
std::cout << crypt( "com", "$1$8KdNUQ4R" ) << std::endl;
return 0;
}
If you want to know how to get it - result of md5 hash of salt + password is converted to string by base64.
slava@bird:~$ g++ crypt.cpp -lcrypt -o crypt_com
slava@bird:~$ ./crypt_com
$1$8KdNUQ4R$ZYyUXVGhvLgVNpfqus.GX/
Upvotes: 5