Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 1 | /* cryptmodule.c - by Steve Majewski |
| 2 | */ |
| 3 | |
Roger E. Masse | 56c345b | 1996-12-09 23:14:26 +0000 | [diff] [blame] | 4 | #include "Python.h" |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 5 | |
| 6 | #include <sys/types.h> |
| 7 | |
| 8 | |
| 9 | /* Module crypt */ |
| 10 | |
| 11 | |
Peter Schneider-Kamp | a788a7f | 2000-07-10 09:57:19 +0000 | [diff] [blame] | 12 | static PyObject *crypt_crypt(PyObject *self, PyObject *args) |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 13 | { |
| 14 | char *word, *salt; |
Thomas Wouters | bd4bc4e | 2000-07-22 23:57:55 +0000 | [diff] [blame] | 15 | extern char * crypt(const char *, const char *); |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 16 | |
Neal Norwitz | ba3a16c | 2002-03-31 15:27:00 +0000 | [diff] [blame] | 17 | if (!PyArg_ParseTuple(args, "ss:crypt", &word, &salt)) { |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 18 | return NULL; |
| 19 | } |
Roger E. Masse | 56c345b | 1996-12-09 23:14:26 +0000 | [diff] [blame] | 20 | return PyString_FromString( crypt( word, salt ) ); |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 21 | |
| 22 | } |
| 23 | |
Fred Drake | a664dbb | 2000-02-01 20:12:39 +0000 | [diff] [blame] | 24 | static char crypt_crypt__doc__[] = "\ |
| 25 | crypt(word, salt) -> string\n\ |
| 26 | word will usually be a user's password. salt is a 2-character string\n\ |
| 27 | which will be used to select one of 4096 variations of DES. The characters\n\ |
| 28 | in salt must be either \".\", \"/\", or an alphanumeric character. Returns\n\ |
| 29 | the hashed password as a string, which will be composed of characters from\n\ |
| 30 | the same alphabet as the salt."; |
| 31 | |
| 32 | |
Roger E. Masse | 56c345b | 1996-12-09 23:14:26 +0000 | [diff] [blame] | 33 | static PyMethodDef crypt_methods[] = { |
Neal Norwitz | ba3a16c | 2002-03-31 15:27:00 +0000 | [diff] [blame] | 34 | {"crypt", crypt_crypt, METH_VARARGS, crypt_crypt__doc__}, |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 35 | {NULL, NULL} /* sentinel */ |
| 36 | }; |
| 37 | |
Guido van Rossum | 3886bb6 | 1998-12-04 18:50:17 +0000 | [diff] [blame] | 38 | DL_EXPORT(void) |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame] | 39 | initcrypt(void) |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 40 | { |
Roger E. Masse | 56c345b | 1996-12-09 23:14:26 +0000 | [diff] [blame] | 41 | Py_InitModule("crypt", crypt_methods); |
Guido van Rossum | e4c6131 | 1994-05-06 14:25:39 +0000 | [diff] [blame] | 42 | } |