Dancer-Plugin-EncodeID
view release on metacpan or search on metacpan
404142434445464748495051525354555657585960
my
$clear_text_id
= decode_id( params->{encoded_id} ) ;
return
"Showing item '$clear_text_id'"
;
};
dance;
FUNCTIONS
`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.
`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.
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
http://myserver.com/item/42 users will see
lib/Dancer/Plugin/EncodeID.pm view on Meta::CPAN
828384858687888990919293949596979899100101102
#print STDERR "Decoding: '$sub_text'\n";
my
$ciphertext
=
pack
(
'H2'
x
scalar
(
@list
),
@list
) ;
my
$text
=
$cipher
->decrypt(
$ciphertext
);
$text
=~ s/^
$padding_character
+//;
#print STDERR "Decoded: '$text'\n";
$cleartext
.=
$text
;
};
if
(
defined
$prefix
) {
## Ensure the decoded ID contains the prefix
my
$i
=
index
$cleartext
,
$prefix
;
if
(
$i
!= 0) {
die
"Invalid Hash-ID value ($orig_encoded_id) - bad prefix"
;
}
#skip the prefix;
$cleartext
=
substr
$cleartext
,
length
(
$prefix
);
}
return
$cleartext
;
};
lib/Dancer/Plugin/EncodeID.pm view on Meta::CPAN
155156157158159160161162163164165166167168169170171172173174175
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.
( run in 0.269 second using v1.01-cache-2.11-cpan-bf8d7bb2d05 )