File: 02-validate.t

package info (click to toggle)
libcrypt-pbkdf2-perl 0.160410-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 156 kB
  • ctags: 45
  • sloc: perl: 589; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 795 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!perl
use strict;
use warnings;

use Test::More;

use constant TEST_PASSWORDS => 500;

BEGIN {
  plan tests => 8 * TEST_PASSWORDS + 1; # + use_ok
  use_ok 'Crypt::PBKDF2';
}

for my $encoding (qw(ldap crypt)) {
  my $pbkdf2 = Crypt::PBKDF2->new(iterations => 40, encoding => $encoding);

  for my $i (1 .. TEST_PASSWORDS) {
    my $password = join "", map ["A".."Z","a".."z","0".."9"]->[rand 62], 1..8;
    my $hash = $pbkdf2->generate($password);
    ok $pbkdf2->validate($hash, $password), "Validate password $i: $password ($encoding)";

    is length $pbkdf2->PBKDF2('test', $password), 20, "raw length $password";
    is length $pbkdf2->PBKDF2_hex('test', $password), 40, "hex length $password";
    is length $pbkdf2->PBKDF2_base64('test', $password), 28, "base64 length $password";
  }
}