static PyObject * user_GenPasswdDes(PyObject *self, PyObject *args) { const char *passwd, *trypasswd; static char pwbuf[DES_PASSLEN]; char *pw; if ( !PyArg_ParseTuple( args, "ss", &passwd, &trypasswd ) ) strlcpy(pwbuf, trypasswd, DES_PASSLEN); pw = crypt_des(pwbuf, (char*) passwd); return PyString_FromString( pw ); }
/* * Hash the given password with the given salt. If the salt begins with a * magic string (e.g. "$6$" for sha512), the corresponding format is used; * otherwise, the currently selected format is used. */ char * crypt(const char *passwd, const char *salt) { const struct crypt_format *cf; #ifdef HAS_DES int len; #endif for (cf = crypt_formats; cf->name != NULL; ++cf) if (cf->magic != NULL && strstr(salt, cf->magic) == salt) return (cf->func(passwd, salt)); #ifdef HAS_DES len = strlen(salt); if ((len == 13 || len == 2) && strspn(salt, DES_SALT_ALPHABET) == len) return (crypt_des(passwd, salt)); #endif return (crypt_format->func(passwd, salt)); }