POE::Component::UserBase - a component to manage user authentication
use POE qw(Component::UserBase); # The UserBase can deal with many types of repositories. # The first kind is a simple file. POE::Component::UserBase->spawn ( Alias => 'userbase', # defaults to 'userbase'. Protocol => 'file', # The repository type. Cipher => 'md5', # defaults to 'crypt'. File => '/home/jgoff/passwd', # The path to the repository Dir => '/home/jgoff/.persist', # Directory to store persistent # information. ); POE::Component::UserBase->spawn ( Alias => 'userbase', # defaults to 'userbase'. Protocol => 'dbi', # The repository type. Cipher => 'sha1', # defaults to 'crypt'. DBHandle => $dbh, # Required, connected to a handle. Table => 'auth', UserColumn => 'user_name', # defaults to 'username'. PassColumn => 'password', # defaults to 'password'. PersistColumn => 'persistent', # defaults to 'data'. This is our # persistent data storage. ); # PoCo::UserBase provides generic user-management services to multiple # sessions. $kernel->post ( user_base => log_on => user_name => $user_name, domain => $domain, # optional password => $password, # optional persistent => $persistent_reference, response => $authorized_state, ); $kernel->post ( user_base => log_off => user_name => $user_name, password => $password, # optional ); $kernel->post ( user_base => create => user_name => $user_name, domain => $domain, # optional password => $password, # optional ); $kernel->post ( user_base => delete => user_name => $user_name, domain => $domain, # optional password => $password, # optional ); $kernel->post ( user_base => update => user_name => $user_name, domain => $domain, # optional password => $password, # optional new_user_name => $new_name, # optional new_domain => $new_dom, # optional new_password => $new_pass, # optional );
POE::Component::UserBase handles basic user authentication and management tasks for a POE server. It can authenticate from sources such as a .htaccess file, database, DBM files, and flat files.
PoCo::UserBase communicates with the client through a previously created SocketFactory. After a client is has connected, PoCo::UserBase interrogates the client for its username and password, and returns the connection data from the socket along with the username and password authenticated.
POE::Component::UserBase's spawn method takes a few parameters to describe the depository of user names. I'd recommend that you not use any crucial system files until you assure yourself that it's indeed safe.
spawn
The spawn method has several common parameters. These are listed below.
Alias sets the name by which the session will be known. If no alias is given, the component defaults to "userbase". The alias lets several sessions interact with the user manager without keeping (or even knowing) hard references to them.
Alias
Cipher sets the cipher that will be used to encrypt the password entries. If no cipher is given, the component defaults to "crypt". This uses the native crypt() function. Other cipher choices include 'md5', 'sha1', 'md5_hex', 'sha1_hex', 'md5_base64', and 'sha1_base64'. The 'md5' and 'sha1' cipher types are documented in the Digest::MD5 and Digest::SHA1 class. They're simply different output formats of the original hash.
Cipher
These parameters are unique to the file Protocol type.
File sets the file name that is used to store user data. This parameter is required.
File
Dir Sets the directory that is used to hold the persistence information. This directory holds the frozen persistent data, indexed by the user_name.
Dir
These parameters are unique to the dbi Protocol type.
Connection stores a handle to a DBI connection. The database must contain a table which will hold the username, password, and persistent data.
Connection
PersistentColumn specifies the column name used to hold the persistent data. If you can't allocate enough space to hold your persistent data in the database, then you can use the DataFile parameter to define a MLDBM file that will be used to hold this persistent data. The MLDBM data file will be keyed by the username.
PersistentColumn
DataFile
DataFile specifies the filename of the MLDBM file used to hold the persistent data store. Use of this parameter is incompatible with Data.
Data
DomainColumn specifies the column used to store the domain column. It defaults to domain.
DomainColumn
domain
PasswordColumn specifies the column used to store the password column. It defaults to password.
PasswordColumn
password
Table specifies the table name used to store username, password, and maybe the persistent data stored along with each user.
Table
UserColumn specifies the column used to store the username column. It defaults to username. In the event that you use the DataFile parameter, this column will be kept in sync with the MLDBM file.
UserColumn
username
Sessions communicate asynchronously with passive UserBase components. They post their requests through several internal states, and receive data through a state that you specify.
Requests are posted to one of the states below:
log_on is to be called when a client wants to authenticate a user.
log_on
$kernel->post ( user_base => log_on => user_name => $user_name, domain => $domain, # optional password => $password, # optional persistent => $persistent_reference, response => $authorized_state, );
log_off is to be called when a client is finished with a user.
log_off
$kernel->post ( user_base => log_off => user_name => $user_name, password => $password, # optional );
create lets you create a new user.
create
$kernel->post ( user_base => create => user_name => $user_name, domain => $domain, # optional password => $password, # optional );
delete lets you delete a user.
delete
$kernel->post ( user_base => delete => user_name => $user_name, domain => $domain, # optional password => $password, # optional );
update lets you update a user.
update
$kernel->post ( user_base => update => user_name => $user_name, domain => $domain, # optional password => $password, # optional new_user_name => $new_name, # optional new_domain => $new_dom, # optional new_password => $new_pass, # optional );
For example, authenticating a user is simply a matter of posting a request to the userBase alias (or whatever you named it). It posts responses back to either the 'authorization accepted' or 'authorizaton failed' state. If it successfully authenticates the user, it then fills the alias referenced in the Persistence parameter with the user data it stored in the database when the user logged out.
userBase
Persistence
This component is built upon POE. Please see its source code and the documentation for its foundation modules to learn more.
Also see the test programs in the t/ directory, and the samples in the samples/ directory in the POE/Component/UserBase directory.
None currently known.
POE::Component::UserBase is Copyright 1999-2000 by Jeff Goff. All rights are reserved. POE::Component::UserBase is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
To install POE::Component::UserBase, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Component::UserBase
CPAN shell
perl -MCPAN -e shell install POE::Component::UserBase
For more information on module installation, please visit the detailed CPAN module installation guide.