blob: 050a356912224b62daca8d4eead354ab8edb2be0 [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
8
9/* Module crypt */
10
11
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +000012static PyObject *crypt_crypt(PyObject *self, PyObject *args)
Guido van Rossume4c61311994-05-06 14:25:39 +000013{
14 char *word, *salt;
Thomas Woutersbd4bc4e2000-07-22 23:57:55 +000015 extern char * crypt(const char *, const char *);
Guido van Rossume4c61311994-05-06 14:25:39 +000016
Neal Norwitzba3a16c2002-03-31 15:27:00 +000017 if (!PyArg_ParseTuple(args, "ss:crypt", &word, &salt)) {
Guido van Rossume4c61311994-05-06 14:25:39 +000018 return NULL;
19 }
Martin v. Löwisf90ae202002-06-11 06:22:31 +000020 /* On some platforms (AtheOS) crypt returns NULL for an invalid
21 salt. Return None in that case. XXX Maybe raise an exception? */
22 return Py_BuildValue("s", crypt(word, salt));
Guido van Rossume4c61311994-05-06 14:25:39 +000023
24}
25
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000026PyDoc_STRVAR(crypt_crypt__doc__,
27"crypt(word, salt) -> string\n\
Fred Drakea664dbb2000-02-01 20:12:39 +000028word will usually be a user's password. salt is a 2-character string\n\
29which will be used to select one of 4096 variations of DES. The characters\n\
30in salt must be either \".\", \"/\", or an alphanumeric character. Returns\n\
31the hashed password as a string, which will be composed of characters from\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000032the same alphabet as the salt.");
Fred Drakea664dbb2000-02-01 20:12:39 +000033
34
Roger E. Masse56c345b1996-12-09 23:14:26 +000035static PyMethodDef crypt_methods[] = {
Neal Norwitzba3a16c2002-03-31 15:27:00 +000036 {"crypt", crypt_crypt, METH_VARARGS, crypt_crypt__doc__},
Guido van Rossume4c61311994-05-06 14:25:39 +000037 {NULL, NULL} /* sentinel */
38};
39
Mark Hammondfe51c6d2002-08-02 02:27:13 +000040PyMODINIT_FUNC
Thomas Woutersf3f33dc2000-07-21 06:00:07 +000041initcrypt(void)
Guido van Rossume4c61311994-05-06 14:25:39 +000042{
Roger E. Masse56c345b1996-12-09 23:14:26 +000043 Py_InitModule("crypt", crypt_methods);
Guido van Rossume4c61311994-05-06 14:25:39 +000044}