[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Checking user-id's and paswords



At 5.48 7/14/97, Jon Warbrick wrote:
>and it works a treat from MacPerl:
>
>  $xxx = &MacPerl'DoAppleScript(<<"EndScript");
>  return (authenticate user name "jon" password "xxx")
>  EndScript
>
>  if ($xxx eq 'true')
>  { print "OK\n";
>  }
>  else
>  { print "Nogo\n";
>  }

Although, you can make it significantly faster:

#!perl
use Benchmark;
$u = 'jon';
$p = 'xxx';

&doStuff;

sub doStuff {
 foreach (\&doAS,\&doAE) {
  $b = new Benchmark;
  &$_;
  $e = new Benchmark;
  print "code took:",timestr(timediff($e,$b)),"\n";
 }
}

sub doAS {
 $xxx = &MacPerl'DoAppleScript(<<"EndScript");
 return (authenticate user name "$u" password "$p")
EndScript

 if ($xxx eq 'true') { print "OK\n"}
 else { print "Nogo\n"}
}

sub doAE {
 use Mac::AppleEvents;
 $be =  AEBuildAppleEvent('QUGL','AUTH',typeApplSignature,'MACS',0,0,
                q"pnam:TEXT(@),PSWD:TEXT(@)",$u,$p) || die "$!\n";
 $rp = AESend($be, kAEWaitReply) or die $^E;
 $xxx = AEPrint(AEGetParamDesc($rp,'----'));
 if ($xxx =~ /01/) { print "OK\n"}  #event returns bool(Ç00È) or bool(Ç01È)
 else { print "Nogo\n"}
}
__END__

Returns:

OK
code took: 1 secs ( 1.73 usr  0.00 sys =  1.73 cpu)
OK
code took: 0 secs ( 0.10 usr  0.00 sys =  0.10 cpu)

As usual, Apple Events are both faster and more difficult to put together.
:-)  And, as usual, the importance of speed in your program dictates which
route you would take.

--
Chris Nandor             pudge@pobox.com             http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch