cryptmodule.c 1.09 KB
Newer Older
1 2 3
/* cryptmodule.c - by Steve Majewski
 */

Roger E. Masse's avatar
Roger E. Masse committed
4
#include "Python.h"
5 6 7 8 9 10 11

#include <sys/types.h>


/* Module crypt */


Peter Schneider-Kamp's avatar
Peter Schneider-Kamp committed
12
static PyObject *crypt_crypt(PyObject *self, PyObject *args)
13 14
{
	char *word, *salt; 
15
	extern char * crypt(const char *, const char *);
16

Neal Norwitz's avatar
Neal Norwitz committed
17
	if (!PyArg_ParseTuple(args, "ss:crypt", &word, &salt)) {
18 19
		return NULL;
	}
20 21 22
	/* On some platforms (AtheOS) crypt returns NULL for an invalid
	   salt. Return None in that case. XXX Maybe raise an exception?  */
	return Py_BuildValue("s", crypt(word, salt));
23 24 25

}

26 27
PyDoc_STRVAR(crypt_crypt__doc__,
"crypt(word, salt) -> string\n\
28 29 30 31
word will usually be a user's password. salt is a 2-character string\n\
which will be used to select one of 4096 variations of DES. The characters\n\
in salt must be either \".\", \"/\", or an alphanumeric character. Returns\n\
the hashed password as a string, which will be composed of characters from\n\
32
the same alphabet as the salt.");
33 34


Roger E. Masse's avatar
Roger E. Masse committed
35
static PyMethodDef crypt_methods[] = {
Neal Norwitz's avatar
Neal Norwitz committed
36
	{"crypt",	crypt_crypt, METH_VARARGS, crypt_crypt__doc__},
37 38 39
	{NULL,		NULL}		/* sentinel */
};

40
PyMODINIT_FUNC
41
initcrypt(void)
42
{
Roger E. Masse's avatar
Roger E. Masse committed
43
	Py_InitModule("crypt", crypt_methods);
44
}