File: compat.t

package info (click to toggle)
libcrypt-bcrypt-perl 0.011-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 160 kB
  • sloc: ansic: 696; perl: 78; makefile: 3
file content (38 lines) | stat: -rw-r--r-- 1,179 bytes parent folder | download
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
27
28
29
30
31
32
33
34
35
36
37
38
use warnings;
use strict;

use Test::More;

use Crypt::Bcrypt qw/bcrypt bcrypt_check/;

use MIME::Base64 'decode_base64';

sub de_base64($) {
	my($text) = @_;
	$text =~ tr#./A-Za-z0-9#A-Za-z0-9+/#;
	return decode_base64($text);
}

my @wrong_passwords = qw(foo quux supercalifragilisticexpialidocious);
while(<DATA>) {
	chomp;
	my ($settings, $hash, $password) = split ' ', $_;
	my ($type, $cost, $encoded_salt) = $settings =~ / ^ \$ (2\w?) \$ (\d+) \$ (.*) $ /x or die $settings;
	my $salt = de_base64($encoded_salt);
	is(bcrypt($password, $type, $cost, $salt), $settings.$hash);
	ok(bcrypt_check($password, $settings.$hash));
	foreach my $wrong_password (@wrong_passwords) {
		isnt(bcrypt($wrong_password, $type, $cost, $salt), $settings.$hash)
	}
}

done_testing;

1;

__DATA__
$2a$05$CCCCCCCCCCCCCCCCCCCCC. E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW U*U
$2a$05$CCCCCCCCCCCCCCCCCCCCC. VGOzA784oUp/Z0DY336zx7pLYAy0lwK U*U*
$2a$05$XXXXXXXXXXXXXXXXXXXXXO AcXxm9kjPGEMsLznoKqmqw7tc8WCx4a U*U*U
$2a$05$CCCCCCCCCCCCCCCCCCCCC. 7uG0VCzI2bS7j6ymqJi9CdcdxiRTWNy 
$2a$05$abcdefghijklmnopqrstuu 5s2v8.iXieOjg/.AySBTTZIIVFJeBui 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789