The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Web::Authenticate::User::Storage::Handler::SQL - Implementation of Web::Authenticate::User::Storage::Handler::Role that can be used with MySQL or SQLite.

VERSION

version 0.013

DESCRIPTION

This Web::Authenticate::User::Storage::Handler::Role is meant to be used with a very specific table structure:

    CREATE TABLE users (
        id INTEGER PRIMARY KEY AUTO_INCREMENT,
        username VARCHAR(255) NOT NULL UNIQUE,
        password TEXT NOT NULL
    );

Other columns can exists, and the names of the table and column can change. But at least these columns must exist in order for this storage handler to work properly. Also, the primary key does not have to be an integer, and could even be the username.

METHODS

users_table

Sets the name of the users table that will be used when querying the database. Default is 'users'.

id_field

Sets the name of the id field that will be used when querying the database. Default is 'id'.

username_field

Sets the name of the username field that will be used when querying the database. Default is 'username'.

password_field

Sets the name of the password field that will be used when querying the database. Default is 'password'.

digest

Sets the Web::Authenticate::Digest::Role that is used. Default is Web::Authenticate::Digest.

dbix_raw

Sets the DBIx::Raw object that will be used to query the database. This is required with no default.

columns

The columns to select. At a minimum, "id_field" and "password_field" will always be selected.

    $user_storage_handler->columns([qw/name age/]);

Default is an empty array ref.

load_user

Accepts the username and password for a user, and returns a Web::Authenticate::User if the password is correct and the user exists. Otherwise, undef is returned. Any additional "columns" will be stored in "row" in Web::Authenticate::User. However, the password will be deleted from the row before it is stored.

    my $user = $user_storage_handler->load_user($username, $password);

load_user_by_id

Loads a user by id.

    my $user = $user_storage_handler->load_user_by_id($user_id);

store_user

Takes in username, password, and any additional values for columns in a hash and we create that user with their hashed password. Returns a Web::Authenticate::User with any values from "columns" stored in "row" in Web::Authenticate::User.

    my $user_values => {
        name => 'Fred',
        age => 34,
        insert_time => \'NOW()', # scalar ref for literal values. See DBIx::Raw
    };
    my $user = $user_storage_handler->store_user($username, $password, $user_vaules);

    # if you need no extra user values in the row
    my $user = $user_storage_handler->store_user($username, $password);

AUTHOR

Adam Hopkins <srchulo@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Adam Hopkins.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.