blob: 746dee15928754a737f184b4441a7372616af72d [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
Roger E. Masse56c345b1996-12-09 23:14:26 +000012static PyObject *crypt_crypt(self, args)
13 PyObject *self, *args;
Guido van Rossume4c61311994-05-06 14:25:39 +000014{
15 char *word, *salt;
16 extern char * crypt();
17
Roger E. Masse56c345b1996-12-09 23:14:26 +000018 if (!PyArg_Parse(args, "(ss)", &word, &salt)) {
Guido van Rossume4c61311994-05-06 14:25:39 +000019 return NULL;
20 }
Roger E. Masse56c345b1996-12-09 23:14:26 +000021 return PyString_FromString( crypt( word, salt ) );
Guido van Rossume4c61311994-05-06 14:25:39 +000022
23}
24
Fred Drakea664dbb2000-02-01 20:12:39 +000025static char crypt_crypt__doc__[] = "\
26crypt(word, salt) -> string\n\
27word will usually be a user's password. salt is a 2-character string\n\
28which will be used to select one of 4096 variations of DES. The characters\n\
29in salt must be either \".\", \"/\", or an alphanumeric character. Returns\n\
30the hashed password as a string, which will be composed of characters from\n\
31the same alphabet as the salt.";
32
33
Roger E. Masse56c345b1996-12-09 23:14:26 +000034static PyMethodDef crypt_methods[] = {
Fred Drakea664dbb2000-02-01 20:12:39 +000035 {"crypt", crypt_crypt, 0, crypt_crypt__doc__},
Guido van Rossume4c61311994-05-06 14:25:39 +000036 {NULL, NULL} /* sentinel */
37};
38
Guido van Rossum3886bb61998-12-04 18:50:17 +000039DL_EXPORT(void)
Guido van Rossume4c61311994-05-06 14:25:39 +000040initcrypt()
41{
Roger E. Masse56c345b1996-12-09 23:14:26 +000042 Py_InitModule("crypt", crypt_methods);
Guido van Rossume4c61311994-05-06 14:25:39 +000043}