Mercurial > pub > Impl
comparison Lib/Security/Auth/Simple.pm @ 0:03e58a454b20
Создан репозитарий
| author | Sergey |
|---|---|
| date | Tue, 14 Jul 2009 12:54:37 +0400 |
| parents | |
| children | 16ada169ca75 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:03e58a454b20 |
|---|---|
| 1 package Security::Auth::Simple; | |
| 2 use strict; | |
| 3 use Common; | |
| 4 | |
| 5 our $Strict; | |
| 6 | |
| 7 our @ISA = qw(Object); | |
| 8 | |
| 9 sub Name { | |
| 10 return 'Simple'; | |
| 11 } | |
| 12 | |
| 13 sub ConstructAuthData { | |
| 14 my ($class,$SecData) = @_; | |
| 15 return new Security::Auth::Simple::AuthData(DataMD5 => $SecData); | |
| 16 } | |
| 17 | |
| 18 sub NewAuthData { | |
| 19 my ($class,$SecData) = @_; | |
| 20 return new Security::Auth::Simple::AuthData(Data => $SecData); | |
| 21 | |
| 22 } | |
| 23 | |
| 24 package Security::Auth::Simple::AuthData; | |
| 25 use Common; | |
| 26 use Security; | |
| 27 use Security::Auth; | |
| 28 use Digest::MD5 qw(md5_hex); | |
| 29 our @ISA = qw(Object); | |
| 30 | |
| 31 BEGIN { | |
| 32 DeclareProperty Data => ACCESS_READ; | |
| 33 DeclareProperty DataMD5 => ACCESS_READ; | |
| 34 } | |
| 35 | |
| 36 sub CTOR { | |
| 37 my ($this,%args) = @_; | |
| 38 | |
| 39 if ($args{'Data'}) { | |
| 40 $args{'DataMD5'}= $args{'Data'} ? md5_hex($args{'Data'}) : undef ; | |
| 41 $this->{$Data} = $args{'Data'}; | |
| 42 } | |
| 43 $this->{$DataMD5} = $args{'DataMD5'}; | |
| 44 } | |
| 45 | |
| 46 sub DoAuth { | |
| 47 my ($this,$SecData) = @_; | |
| 48 | |
| 49 if (not ($this->{$DataMD5} or $SecData) or $this->{$DataMD5} eq md5_hex($SecData)) { | |
| 50 if ($Strict) { | |
| 51 $this->{$Data} = Security::Auth::GenSSID; | |
| 52 $this->{$DataMD5} = md5_hex($this->{$Data}); | |
| 53 } else { | |
| 54 $this->{$Data} = $SecData; | |
| 55 } | |
| 56 return Security::AUTH_SUCCESS; | |
| 57 } else { | |
| 58 return Security::AUTH_FAILED; | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 sub SessionAuthData { | |
| 63 my ($this) = @_; | |
| 64 | |
| 65 return $this->{$DataMD5}; | |
| 66 } | |
| 67 | |
| 68 sub ClientAuthData { | |
| 69 my ($this) = @_; | |
| 70 return $this->{$Data}; | |
| 71 } | |
| 72 | |
| 73 1; |
