home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / FAQ / discus_admin_1357211388 / source / emergpw.pl < prev    next >
Text File  |  2009-11-06  |  2KB  |  73 lines

  1. # FILE: emergpw.pl
  2. # DESCRIPTION: Emergency Password access
  3. #-------------------------------------------------------------------------------
  4. # DISCUS COPYRIGHT NOTICE
  5. #
  6. # Discus is copyright (c) 2002 by DiscusWare, LLC, all rights reserved.
  7. # The use of Discus is governed by the Discus License Agreement which is
  8. # available from the Discus WWW site at:
  9. #    http://www.discusware.com/discus/license
  10. #
  11. # Pursuant to the Discus License Agreement, this copyright notice may not be
  12. # removed or altered in any way.
  13. #-------------------------------------------------------------------------------
  14.  
  15. use strict;
  16. use vars qw($GLOBAL_OPTIONS $DCONF $PARAMS);
  17.  
  18. ###
  19. ### make_emergency_password
  20. ###
  21. ### Generates a random "emergency" password and associated text file
  22. ###
  23.  
  24. sub make_emergency_password {
  25.     my $FORMref = $_[0];
  26.     if (! defined $FORMref->{encpw}) {
  27.         dreq("fcn-acct", "authpass");
  28.         my ($pass, $salt);
  29.         while ($pass =~ /[0o]/i || $pass !~ /\d[a-z]+\d/i || $pass =~ /\d\d\d/i) {
  30.             ($pass, $salt) = pick_random_password();
  31.         }
  32.         my $subst = {};
  33.         $subst->{general}->{plainpass} = $pass;
  34.         $pass = prepare_userpass_p($pass);
  35.         $subst->{general}->{password} = crypt($pass, $salt);
  36.         screen_out("emerg", $subst);
  37.     } else {
  38.         header(undef, "text/plain", "emergency.txt");
  39.         print "\r\n:::$FORMref->{encpw}:::\r\n";    
  40.         program_exit(0);
  41.     }    
  42. }
  43.  
  44. ###
  45. ### validate_emergency_password
  46. ###
  47. ### Checks to see if an emergency password is correct
  48. ###
  49.  
  50. sub validate_emergency_password {
  51.     my ($password, $cookies, $args) = @_;
  52.     my $file_mtime = (stat "$DCONF->{admin_dir}/data/emergency.txt")[9];
  53.     if (time - $file_mtime > 3600) {
  54.         unlink "$DCONF->{admin_dir}/data/emergency.txt";
  55.         return "";
  56.     }
  57.     my @z = grep { /:::/ } @{readfile("$DCONF->{admin_dir}/data/emergency.txt","validate_emergency_password",{no_lock=>1,no_unlock=>1,zero_ok=>1})};
  58.     return "" if ! scalar @z;
  59.     return "" if $z[0] !~ /:::(.*?):::/;
  60.     my $pwcrypt = $1;
  61.     if (defined $password) {
  62.         dreq("authpass");
  63.         return $pwcrypt if crypt($password, $pwcrypt) eq $pwcrypt;
  64.         return "" if $password ne "" && $password ne "adminlogin";        
  65.     }
  66.     if (defined $cookies->{pass}) {
  67.         return $pwcrypt if $cookies->{pass} eq crypt($pwcrypt, "cookie")
  68.     }
  69.     return "";    
  70. }
  71.  
  72. 1;
  73.