Sunday, July 04, 2004

c/c++/linux :: char *crypt(char *, char *)

/** \brief
* crypt fucntion
* used to crypt a key, uselful for linux password
*
* linux uses salt for crypting
* a typical linux shadow password looks like (without quotes)
* "$1$ptqYz.X.$Cspm6f.AE7b.pQuM17JOk/"
*
* note the three $'s (dollar signs in the password)
* theese are used to distinguish salt and hash
* $1$ says that a 8 characters long salt follows it
* so in the above password salt is "ptqYz.X."
*
* so in the crypt function i am providing the above salt prefixed
* with $1$. for crypt function $1$ means that a md5sum will be used
* to crypt the key.
*
* the password "lakshya" with the above salt will produce the above
* crypted password
*
* md5sum is 22 characters long
*/

#define _XOPEN_SOURCE
#include

int main(int argc, char **argv)
{
printf("<%s>\n",crypt("lakshya","$1$ptqYz.X."));
return 0;
}