| Aut documentation | Contained in the Aut distribution. |
account() --> stringpass() --> stringseed() --> stringget(var) --> stringset_rights(_rights) --> voidset_pass(_pass) --> voidset_seed(_seed) --> voidset(var,val) --> voiddecrypt(ciphertext) --> stringAut::Ticket - Authorization Framework - Tickets
See Aut. =head1 ABSTRACT
'Aut::Ticket' is part of the 'Aut' authorization framework It provides tickets that are the user's access to services and application parts. It also provides encryption/decryption for user data.
seed in the
Aut::Ticket context, is a (random) value of 32 digits, that is generated when
a new ticket is made and can be set through public methods. new(account,password) --> Aut::TicketThis method initializes a ticket with a given account and password and generates a new seed.
valid() --> booleanReturns true, if the ticket is valid, returns False, otherwise.
rights() --> stringReturns the currently assigned "rights" value to this ticket.
account() --> stringReturns the currently assigned account for this ticket.
pass() --> stringReturns the currently assigned password for this ticket.
seed() --> stringReturns the seed value of this ticket that is being used for encryption/decryption.
get(var) --> stringGets value for 'var' from the ticket.
invalidate() --> voidInvalidates a ticket.
set_rights(_rights) --> voidSets the rights value of the ticket to _rights.
set_pass(_pass) --> voidSets the password of the ticket to _pass.
set_seed(_seed) --> voidSets the seed value of the ticket (the encryption key) to _seed.
set(var,val) --> voidSets a variable 'var' in the ticket to value 'val'.
encrypt(text) --> base64 stringEncrypts text using Aut::Crypt, with key seed(); returns
a base64 encoded (with Aut::Base64) encrypted string.
decrypt(ciphertext) --> stringDecrypts text using Aut::Crypt, after it has been decoded
with Aut::Base64. If the decryption is valid, it returns
the decrypted string, otherwise undef is returned.
Hans Oesterholt-Dijkema <oesterhol@cpan.org>
This library is free software; you can redistribute it and/or modify it under Artistic license.
| Aut documentation | Contained in the Aut distribution. |
package Aut::Ticket; use strict; use Aut::Base64; use Aut::Crypt; srand(time()); sub new { my $class=shift; my $account=shift; my $pass=shift; my $self; $self->{"conf"}->{"aut"}="there"; $self->{"pass"}=$pass; $self->{"account"}=$account; $self->{"valid"}=1; my $s=""; while (length($s)<32) { $s.=rand(); $s=~s/[^0-9]//g; } $s=substr($s,0,32); $self->{"seed"}=$s; bless $self,$class; return $self; } sub invalidate { my $self=shift; $self->{"valid"}=0; } sub valid { my $self=shift; return $self->{"valid"}; } sub rights { my $self=shift; return $self->{"rights"}; } sub account { my $self=shift; return $self->{"account"}; } sub pass { my $self=shift; return $self->{"pass"}; } sub seed { my $self=shift; return $self->{"seed"}; } sub set_rights { my $self=shift; my $rights=shift; $self->{"rights"}=$rights; } sub set_seed { my $self=shift; my $seed=shift; $self->{"seed"}=$seed; } sub set_pass { my $self=shift; my $pass=shift; $self->{"pass"}=$pass; } sub gen6 { my $r=""; while (length $r lt 6) { $r.=rand(); $r=~s/[.]//; $r=~s/^0//; } $r=substr($r,0,6); return $r; } sub encrypt { my $self=shift; my $text=shift; my $crypter=new Aut::Crypt($self->seed()); my $base64=new Aut::Base64(); my $r=gen6(); return $base64->encode($crypter->encrypt("$r$r".$text)); } sub decrypt { my $self=shift; my $text=shift; my $dtext; my $crypter=new Aut::Crypt($self->seed()); my $base64=new Aut::Base64(); $dtext=$crypter->decrypt($base64->decode($text)); my $r1=substr($dtext,0,6); my $r2=substr($dtext,6,6); if ($r1 ne $r2) { return undef; } else { return substr($dtext,12,length($dtext)); } } sub set { my $self=shift; my $var=shift; my $val=shift; $self->{"conf"}->{$var}=$val; } sub get { my $self=shift; my $var=shift; return $self->{"conf"}->{$var}; } 1; __END__