home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / linux / apache / contrib / modules / pg95passwd.pl < prev    next >
Encoding:
Perl Script  |  1998-06-11  |  2.1 KB  |  106 lines

  1. #!/usr/local/bin/perl
  2.  
  3. # pg95passwd.pl - David H. Bennett - dave@bensoft.com - Version 1.0
  4. #
  5. # This program will create password entries that can be used by 
  6. # the mod_auth_pg95.c module for the Apache web server.
  7. #
  8. # You can get the latest version from:
  9. #   ftp://ftp.bensoft.com/apache/pg95passwd.pl
  10. #
  11. # Requires:
  12. #   Perl 5
  13. #   Postgres95          
  14. #   Apache web server
  15. #   pg95perl library
  16. #
  17.  
  18. use Pg;
  19.  
  20. # --- Edit these values to suit your needs ---
  21.  
  22. $pghost    = 'localhost';
  23. $pgport    = '5432';
  24. $pgoptions = '';
  25. $pgtty   = '';
  26. $dbname    = 'my_database';
  27.  
  28. $tablename = 'my_table';
  29. $uidfield = 'login';
  30. $passfield = 'password';
  31.  
  32. # --- Don't edit below this line ---
  33.  
  34. # these are from libpq-fe.h
  35.  
  36. $PGRES_EMPTY_QUERY= 0 ;
  37. $PGRES_COMMAND_OK= 1 ;
  38. $PGRES_TUPLES_OK= 2 ;
  39. $PGRES_COPY_OUT= 3 ;
  40. $PGRES_COPY_IN= 4 ;
  41. $PGRES_BAD_RESPONSE   = 5 ;
  42. $PGRES_NONFATAL_ERROR = 6 ;
  43. $PGRES_FATAL_ERROR= 7 ;
  44.  
  45. # Calculate salt value for crypt function
  46. #
  47. @saltair= split
  48.   //,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcedfghijklmnopqrstuvwxyz0123456789./";
  49. sub get_salt {
  50.   srand();
  51.   $iOff = int(rand($#saltair));
  52.   $iOff2 = int(rand($#saltair));
  53.   return join("",$saltair[$iOff],$saltair[$iOff2]);
  54. }
  55.  
  56. sub PGError {
  57.   print "Database Access Error: ", @_;
  58.   exit;
  59. }
  60.  
  61. # specify the database to access
  62. $conn = PQsetdb ($pghost, $pgport, $pgoptions, $pgtty, $dbname);
  63. &PGError() if PQstatus($conn);
  64.  
  65. $strUID=$ARGV[0];
  66.  
  67. if ($strUID eq "") {
  68.   print "Usage: pg95passwd.pl {user name}\n";
  69.   print "\n";
  70.   exit;
  71. }
  72.  
  73. # Get the password from the user
  74. #
  75.  
  76. print "Please input the password: ";
  77. $strEnterPass = <STDIN>;
  78. chop $strEnterPass;
  79.  
  80. print "Re-type the password: ";
  81. $strEnterPass2 = <STDIN>;
  82. chop $strEnterPass2;
  83.  
  84. if ($strEnterPass ne $strEnterPass2) {
  85.   print "Passwords are not identical!\n";
  86.   exit;
  87. }
  88.  
  89. # Delete the user record if it exists.
  90. $cmd = "delete from $tablename where $uidfield = '$strUID'";
  91. PQexec($conn, $cmd);
  92.  
  93. # Encrypt the password entered
  94. $strCryptPass = crypt($strEnterPass,get_salt());
  95.  
  96. # Insert it into the database
  97. #
  98. $cmd = "insert into $tablename ($uidfield,$passfield) values ('$strUID','$strCryptPass')";
  99. PQexec($conn, $cmd);
  100.  
  101. print "Password Revised!\n";
  102.  
  103. PQfinish($conn);
  104.