This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Perl references

By: a guest on Feb 25th, 2011  |  syntax: Perl  |  size: 2.02 KB  |  views: 70  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. # Utils.pm
  3. ####################
  4. sub AuthenticateUser
  5. {
  6.     my $user = shift;
  7.     my $passwd = shift;
  8.     my $privs = shift;
  9.     my $res;
  10.     my $authlink = $Globals::baseurl."/cgi-bin/auth.pl";
  11.     # now we have to authenticate the user
  12.     $res = CGI_ats::GetUserandPasswd(\$user, \$passwd, \$privs);
  13.     #$res = 1;
  14.     if (!$res)
  15.     {
  16.         print  "<meta http-equiv=\"REFRESH\"content=\"0;url=$authlink?caller=".$CGI_at$
  17.         Utils::HTMLFailure("Failed to get cookie info", 1);
  18.     }
  19.  
  20.     return($res);
  21. }
  22. ################
  23.  
  24. # CGIats.pm
  25.  
  26. sub GetUserandPasswd
  27. {
  28.     my ($user, $password, $privs) = @_;
  29.  
  30.     my $cookie = $CGI_ats::query->cookie($CGI_ats::ats_cookie_name);
  31.  
  32.     #Check it was defined
  33.     if(! defined $cookie)
  34.     {
  35.         Utils::HTMLFailure("Failed to get $CGI_ats::ats_cookie_name cookie");
  36.         return 0;
  37.     }
  38.  
  39.     my @cookie_content = split(/\,/, MIME::Base64::decode($cookie));
  40.  
  41.     # check if had valid content
  42.     if(! scalar @cookie_content)
  43.     {
  44.         Utils::HTMLFailure("Failed to get $CGI_ats::ats_cookie_name cookie");
  45.         return 0;
  46.     }
  47.  
  48.     $$user     = $cookie_content[0];
  49.     $$password = MIME::Base64::decode($cookie_content[1]);
  50.     $$privs    = $cookie_content[2];
  51.  
  52.     return 1;
  53.  
  54. }
  55. ##############
  56. # auth.pl
  57. if(defined $CGI_ats::query->param('op'))
  58. {
  59.     if($CGI_ats::query->param('op') eq 'login')
  60.     {
  61.         # make sure we have a name and password before we
  62.         # enter the poll loop
  63.         if(! defined $CGI_ats::query->param('name')   ||
  64.            ! $CGI_ats::query->param('name')           ||
  65.            ! defined $CGI_ats::query->param('passwd') ||
  66.            ! $CGI_ats::query->param('passwd'))
  67.         {
  68.             $error_text = "<p>User name and password not supplied</p>\n";
  69.         }
  70.         else
  71.         {
  72.             # we have to enter a poll loop to do this
  73.             enter_poll();
  74.         }
  75. ###############
  76.  
  77. # results.pl
  78. $res = Utils::AuthenticateUser(\$user, \$passwd, \$privs);
  79. if (!$res)
  80. {
  81.     exit(1);
  82. }
clone this paste RAW Paste Data