Connecting Tech Pros Worldwide Help | Site Map

Admin login security code

Newbie
 
Join Date: Oct 2007
Posts: 2
#1: Oct 18 '07
Hi there,

I am Gerard, 1st year student of Perl at the university.
I came across some lines of code from a script done by an ex student that left uni and did not left any explanation of the code.

The only thing I know is that the script reads an external file that contains 2 lines of code.
The 1st and 2nd lines on this file are:


BEGIN!! Addr:* Name:John
-
4DZWJMZMX44ZiaZ4 END!!

I think it compares both lines on the script and return true if equal.

Could some one please explain me better, and how can I create the second line? is it in HExadecimal or what?

Below is the code on the script:

Expand|Select|Wrap|Line Numbers
  1.  
  2. $const{'code_validate'} = sub {
  3.     my $p_decode = sub {
  4.         local $_;
  5.         my $code = defined($_[0]) ? $_[0] : '';
  6.         my %map = ();
  7.         my $i = 0;
  8.         foreach (48..57,65..90,97..122) {
  9.             $map{chr($_)} = $i % 16;
  10.             $i++;
  11.         }
  12.         $code =~ s!\s|\r|\n|\015|\012!!sg;
  13.         my $text = '';
  14.         my $frag = '';
  15.         $i = 0;
  16.         while ($frag = substr($code, $i, 2)) {
  17.             $i += 2;
  18.             my $chn = 16 * $map{substr($frag,0,1)};
  19.             $chn += $map{substr($frag,1,1)};
  20.             my $ch = chr($chn);
  21.             $text .= $ch;
  22.         }
  23.         $text = unpack('u',$text);
  24.         return $text;
  25.     };
  26.     local $_;
  27.     my $code = defined($_[0]) ? $_[0] : '';
  28.     return 0 unless ($code);
  29.     my $is_valid = 0;
  30.     $code =~ s!BEGIN!!sg;
  31.     $code =~ s!END!!sg;
  32.     if ($code =~ m!^\s*(.*)\s*\-\s*(.*?)\s*$!s) {
  33.         my ($pub, $pri) = ($1,$2);
  34.         $pri = &$p_decode($pri);
  35.         $pub =~ s!(\s|\r|\n)!!sg;
  36.         $pri =~ s!(\s|\r|\n)!!sg;
  37.         if ($pub eq $pri) {
  38.             $is_valid = 1;
  39.         }
  40.     }
  41.     return $is_valid;
  42. };
  43.  

Thanks for all your help
Gerard
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#2: Oct 19 '07

re: Admin login security code


same stuff you posted on perlguru where I said that the code you posted seemed to have nothing to do with the question you asked.

There is no need to use that code for anything I can think of.
Newbie
 
Join Date: Oct 2007
Posts: 2
#3: Oct 20 '07

re: Admin login security code


Hi Kevin

The script I use reads the text file and compares both lines(like the ones above the code), than if those lines are equal the script assign administrator privileges or secretary priv.

I just would like to know how can I create a script to create the what I think is the hexadecimal code from the second line equal to the written text from the first line.

In that way I can create more privileges to other students according to their Year of studies.

Regards Gerard
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#4: Oct 20 '07

re: Admin login security code


Sorry, the code is quite confusing. Too bad the author didn't include some comments.
Reply