UserDB - A simple users and groups management interface
use UserDB; my $userdb = UserDB->new("user.db"); # Connect to the database if(!$userdb) { die "Could not connect to database!"; } $userdb->create_user("tanya"); # Create a new user $userdb->set_attributes("tanya", name => "Tanya Harding", email => "tanya.harding\@example.com"); # Set some attributes my %attrs = $userdb->get_attributes("tanya"); # Get attributes print "Name: " . $attrs{"name"} . "\n"; print "Email: " . $attrs{"email"} . "\n"; print "Department: " . $attrs{"department"} . "\n"; $userdb->create_group("Finance Staff"); # Create a group $userdb->add_to_group("tanya", "Finance Staff"); # Add user to group $userdb->create_user("joe"); # Create a new user $userdb->add_to_group("joe", "Finance Staff"); # Add the new user to group foreach my $member ($userdb->members_of_group("Finance Staff")) # List members of group { print "Finance Staff contains: " . $member . "\n"; $userdb->remove_from_group($member, "Finance Staff"); # Remove member from the group } $userdb->set_password("joe", "Test123"); # Set a password if($userdb->check_password("joe", "Test321")) # Verify the password { print "Login successful!\n"; } else { print "Login failed! " . $userdb->error . "\n"; }
UserDB is a simple management module for users and groups. It uses a flat file database to store information and as such does not rely on any external resource. It provides an interface to do simple functions for implementing users and groups, and handles errors gracefully. Any method can return 'undef' in case an error happened, the expected value (or true) otherwise.
Create or open an existing UserDB file.
Returns the last error message.
Create a new user.
Set attributes for a user. The available attributes include: name, email, profile, phone, manager, department, url, notes.
Returns an associative array of attributes for the user.
Set a user password. The password is hashed before being stored.
Check a user password against the stored one.
Return a full list of users.
Create a new group.
Add a user to a group.
Remove a user from a group.
Returns an array of members for a group.
Patrick Lambert, <dendory@live.ca>
Copyright (C) 2014 by Patrick Lambert
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.16.3 or, at your option, any later version of Perl 5 you may have available.
4 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
To install UserDB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm UserDB
CPAN shell
perl -MCPAN -e shell install UserDB
For more information on module installation, please visit the detailed CPAN module installation guide.