Dancer-Plugin-EncodeID

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
                    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

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
                #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

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
                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>
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 )