home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / Python2 / Python20_source / Modules / cryptmodule.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-25  |  1.2 KB  |  55 lines

  1. /* cryptmodule.c - by Steve Majewski
  2.  */
  3.  
  4. #include "Python.h"
  5.  
  6. #include <sys/types.h>
  7.  
  8. #ifdef AMITCP
  9. #include <proto/usergroup.h>
  10. #endif
  11. #ifdef INET225
  12. #include <proto/socket.h>
  13. static __inline STRPTR crypt(STRPTR pw, STRPTR un)
  14. {
  15.     static char buf[32];
  16.     return s_crypt(buf,pw,un);
  17. }
  18. #endif
  19.  
  20.  
  21. /* Module crypt */
  22.  
  23.  
  24. static PyObject *crypt_crypt(PyObject *self, PyObject *args)
  25. {
  26.     char *word, *salt; 
  27.     extern char * crypt(const char *, const char *);
  28.  
  29.     if (!PyArg_Parse(args, "(ss)", &word, &salt)) {
  30.         return NULL;
  31.     }
  32.     return PyString_FromString( crypt( word, salt ) );
  33.  
  34. }
  35.  
  36. static char crypt_crypt__doc__[] = "\
  37. crypt(word, salt) -> string\n\
  38. word will usually be a user's password. salt is a 2-character string\n\
  39. which will be used to select one of 4096 variations of DES. The characters\n\
  40. in salt must be either \".\", \"/\", or an alphanumeric character. Returns\n\
  41. the hashed password as a string, which will be composed of characters from\n\
  42. the same alphabet as the salt.";
  43.  
  44.  
  45. static PyMethodDef crypt_methods[] = {
  46.     {"crypt",    crypt_crypt, METH_OLDARGS, crypt_crypt__doc__},
  47.     {NULL,        NULL}        /* sentinel */
  48. };
  49.  
  50. DL_EXPORT(void)
  51. initcrypt(void)
  52. {
  53.     Py_InitModule("crypt", crypt_methods);
  54. }
  55.