Dancer-Plugin-EncodeID

 view release on metacpan or  search on metacpan

lib/Dancer/Plugin/EncodeID.pm  view on Meta::CPAN


		# Encode the ID, generate the URL
		my $encoded_id = encode_id($clear_text_id);
		my $url = request->uri_for("/item/$encoded_id");

		return "Link for Item $clear_text_id: <a href=\"$url\">$url</a>";
	};

	#
	# Decode a given ID, show the requested item
	#
	get '/item/:encoded_id' => sub {
		# Decode the ID back to clear-text
		my $clear_text_id = decode_id( params->{encoded_id} ) ;

		return "Showing item '$clear_text_id'";
	};

	dance;

=head1 FUNCTIONS

C<encode_id(ID [,PREFIX])> - Encodes the given ID, returns the encoded hash value.
			     If "PREFIX" is given, it will be added to the ID before encoding.
			     It can be used when decoding to verify the decoded value is valid.

C<decode_id(ID [,PREFIX])> - Decodes the given ID, returns the original (cleartext) ID value.
			     If "PREFIX" is given, it will be used to verify the validity of the ID.

=head1 DESCRIPTION

This module aims to make it as easy as possible to obfuscate internal IDs
when using them in a URL given to users. Instead of seeing L<http://myserver.com/item/42>
users will see L<http://myserver.com/item/c98ea08a8e8ad715> .
This will prevent nosy users from trying to iterate all items based on a simple ID in the URL.

=head1 CONFIGURATION

Configuration requires a secret key at a minimum.

Either put this in your F<config.yml> file:

    plugins:
      EncodeID:
        secret: 'my_secret_password'

Or set the secret key at run time, with:

    setting plugins => { EncodeID => { secret => 'my_secret_code' } };

=head1 AUTHOR

Assaf Gordon, C<< <gordon at cshl.edu> >>

=head1 BUGS

=over

=item THIS MODULE IS NOT SECURE. The encoded ID are not strongly encrypted in any way. The goal is obfuscation, not security.

=item A possible improvement would be to use L<Crypt::CBC> on top of L<Crypt::Blowfish>, but that would generate IDs that are at least 48 characters long.

=item The secret key can not be changed once loaded.

=back

Please report any bugs or feature requests to
L<https://github.com/agordon/Dancer-Plugin-EncodeID/issues>

=head1 SEE ALSO

A fully functional command-line tool to encode/decode IDs is available in the C<./eg/> folder.

L<Dancer>, L<Dancer::Plugin>

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Dancer::Plugin::EncodeID

=head1 ACKNOWLEDGEMENTS

Idea and implementation for this module were greatly influenced by similar mechanism used in the Galaxy project (L<http://usegalaxy.org>).

=head1 LICENSE AND COPYRIGHT

Copyright 2011 Assaf Gordon.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

=cut



( run in 1.330 second using v1.01-cache-2.11-cpan-e1769b4cff6 )