Aut::Ticket - Authorization Framework - Tickets


Aut documentation Contained in the Aut distribution.

Index


Code Index:

NAME

Top

Aut::Ticket - Authorization Framework - Tickets

SYNOPSIS

Top

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.

DESCRIPTION

Top

Instantiating

new(account,password) --> Aut::Ticket

This method initializes a ticket with a given account and password and generates a new seed.

Querying

valid() --> boolean

Returns true, if the ticket is valid, returns False, otherwise.

rights() --> string

Returns the currently assigned "rights" value to this ticket.

account() --> string

Returns the currently assigned account for this ticket.

pass() --> string

Returns the currently assigned password for this ticket.

seed() --> string

Returns the seed value of this ticket that is being used for encryption/decryption.

get(var) --> string

Gets value for 'var' from the ticket.

Setting

invalidate() --> void

Invalidates a ticket.

set_rights(_rights) --> void

Sets the rights value of the ticket to _rights.

set_pass(_pass) --> void

Sets the password of the ticket to _pass.

set_seed(_seed) --> void

Sets the seed value of the ticket (the encryption key) to _seed.

set(var,val) --> void

Sets a variable 'var' in the ticket to value 'val'.

Encryption/Decryption

encrypt(text) --> base64 string

Encrypts text using Aut::Crypt, with key seed(); returns a base64 encoded (with Aut::Base64) encrypted string.

decrypt(ciphertext) --> string

Decrypts 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.

SEE ALSO

Top

Aut framework, Aut::Base64, Aut::Crypt.

AUTHOR

Top

Hans Oesterholt-Dijkema <oesterhol@cpan.org>

COPYRIGHT AND LICENSE

Top


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__