blob: 62aa06cd8567baf15f59bc3b84584ced36137e89 [file] [log] [blame]
Guido van Rossume4c61311994-05-06 14:25:39 +00001/* cryptmodule.c - by Steve Majewski
2 */
3
Roger E. Masse56c345b1996-12-09 23:14:26 +00004#include "Python.h"
Guido van Rossume4c61311994-05-06 14:25:39 +00005
6#include <sys/types.h>
7
Guido van Rossume4c61311994-05-06 14:25:39 +00008/* Module crypt */
9
10
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +000011static PyObject *crypt_crypt(PyObject *self, PyObject *args)
Guido van Rossume4c61311994-05-06 14:25:39 +000012{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000013 char *word, *salt;
Guido van Rossume4c61311994-05-06 14:25:39 +000014
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000015 if (!PyArg_ParseTuple(args, "ss:crypt", &word, &salt)) {
16 return NULL;
17 }
18 /* On some platforms (AtheOS) crypt returns NULL for an invalid
19 salt. Return None in that case. XXX Maybe raise an exception? */
20 return Py_BuildValue("s", crypt(word, salt));
Guido van Rossume4c61311994-05-06 14:25:39 +000021
22}
23
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000024PyDoc_STRVAR(crypt_crypt__doc__,
25"crypt(word, salt) -> string\n\
Fred Drakea664dbb2000-02-01 20:12:39 +000026word will usually be a user's password. salt is a 2-character string\n\
27which will be used to select one of 4096 variations of DES. The characters\n\
28in salt must be either \".\", \"/\", or an alphanumeric character. Returns\n\
29the hashed password as a string, which will be composed of characters from\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000030the same alphabet as the salt.");
Fred Drakea664dbb2000-02-01 20:12:39 +000031
32
Roger E. Masse56c345b1996-12-09 23:14:26 +000033static PyMethodDef crypt_methods[] = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000034 {"crypt", crypt_crypt, METH_VARARGS, crypt_crypt__doc__},
35 {NULL, NULL} /* sentinel */
Guido van Rossume4c61311994-05-06 14:25:39 +000036};
37
Martin v. Löwis1a214512008-06-11 05:26:20 +000038
39static struct PyModuleDef cryptmodule = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000040 PyModuleDef_HEAD_INIT,
Sean Reifscheidere2dfefb2011-02-22 10:55:44 +000041 "_crypt",
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000042 NULL,
43 -1,
44 crypt_methods,
45 NULL,
46 NULL,
47 NULL,
48 NULL
Martin v. Löwis1a214512008-06-11 05:26:20 +000049};
50
Mark Hammondfe51c6d2002-08-02 02:27:13 +000051PyMODINIT_FUNC
Sean Reifscheidere2dfefb2011-02-22 10:55:44 +000052PyInit__crypt(void)
Guido van Rossume4c61311994-05-06 14:25:39 +000053{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000054 return PyModule_Create(&cryptmodule);
Guido van Rossume4c61311994-05-06 14:25:39 +000055}