« blib/lib/Web/Authenticate/Cookie/Handler/Role.pm
↑ Summary
blib/lib/Web/Authenticate/Digest/Role.pm »
| 1 | use strict; | ||
| 2 | package Web::Authenticate::Digest; | ||
| 3 | $Web::Authenticate::Digest::VERSION = '0.003'; | ||
| 4 | use Mouse; | ||
| 5 | use Mouse::Util::TypeConstraints; | ||
| 6 | use Crypt::PBKDF2; | ||
| 7 | #ABSTRACT: The default implementation of Web::Authenticate::Digest::Role. | ||
| 8 | |||
| 9 | with 'Web::Authenticate::Digest::Role'; | ||
| 10 | |||
| 11 | |||
| 12 | has crypt => ( | ||
| 13 | isa => 'Crypt::PBKDF2', | ||
| 14 | is => 'ro', | ||
| 15 | required => 1, | ||
| 16 | default => sub { | ||
| 17 | Crypt::PBKDF2->new( | ||
| 18 | hash_class => 'HMACSHA2', | ||
| 19 | hash_args => { | ||
| 20 | sha_size => 512, | ||
| 21 | }, | ||
| 22 | iterations => 10000, | ||
| 23 | salt_len => 10, | ||
| 24 | ); | ||
| 25 | }, | ||
| 26 | ); | ||
| 27 | |||
| 28 | |||
| 29 | sub generate { | ||
| 30 | my ($self, $password) = @_; | ||
| 31 | return $self->crypt->generate($password); | ||
| 32 | } | ||
| 33 | |||
| 34 | |||
| 35 | sub validate { | ||
| 36 | my ($self, $hash, $password) = @_; | ||
| 37 | return $self->crypt->validate($hash, $password); | ||
| 38 | } | ||
| 39 | |||
| 40 | 1; | ||
| 41 | |||
| 42 | __END__ | ||
| 43 | |||
| 44 | =pod | ||
| 45 | |||
| 46 | =encoding UTF-8 | ||
| 47 | |||
| 48 | =head1 NAME | ||
| 49 | |||
| 50 | Web::Authenticate::Digest - The default implementation of Web::Authenticate::Digest::Role. | ||
| 51 | |||
| 52 | =head1 VERSION | ||
| 53 | |||
| 54 | version 0.003 | ||
| 55 | |||
| 56 | =head1 METHODS | ||
| 57 | |||
| 58 | =head2 crypt | ||
| 59 | |||
| 60 | Sets the L<Crypt::PBKDF2> object that is used to create and validate digests. Below is the default: | ||
| 61 | |||
| 62 | Crypt::PBKDF2->new( | ||
| 63 | hash_class => 'HMACSHA2', | ||
| 64 | hash_args => { | ||
| 65 | sha_size => 512, | ||
| 66 | }, | ||
| 67 | iterations => 10000, | ||
| 68 | salt_len => 10, | ||
| 69 | ) | ||
| 70 | |||
| 71 | =head2 generate | ||
| 72 | |||
| 73 | Accepts a password and returns the hex digest of that password using L</crypt>. | ||
| 74 | |||
| 75 | my $password_digest = $digest->generate($password); | ||
| 76 | |||
| 77 | =head2 | ||
| 78 | |||
| 79 | Uses L<Crypt::PBKDF2/"validate">. | ||
| 80 | |||
| 81 | my $validate_success = $digest->validate($hash, $password); | ||
| 82 | |||
| 83 | =head1 AUTHOR | ||
| 84 | |||
| 85 | Adam Hopkins <srchulo@cpan.org> | ||
| 86 | |||
| 87 | =head1 COPYRIGHT AND LICENSE | ||
| 88 | |||
| 89 | This software is copyright (c) 2017 by Adam Hopkins. | ||
| 90 | |||
| 91 | This is free software; you can redistribute it and/or modify it under | ||
| 92 | the same terms as the Perl 5 programming language system itself. | ||
| 93 | |||
| 94 | =cut |