Authen-Passphrase

 view release on metacpan or  search on metacpan

lib/Authen/Passphrase/LANManager.pm  view on Meta::CPAN

			croak "hash specified redundantly"
				if defined($hash) || defined($passphrase);
			$value =~ m#\A[\x00-\xff]{16}\z#
				or croak "not a valid LAN Manager hash";
			$hash = $value;
		} elsif($attr eq "hash_hex") {
			croak "hash specified redundantly"
				if defined($hash) || defined($passphrase);
			$value =~ m#\A[0-9A-Fa-f]{32}\z#
				or croak "\"$value\" is not a valid ".
						"hex LAN Manager hash";
			$hash = pack("H*", $value);
		} elsif($attr eq "passphrase") {
			croak "passphrase specified redundantly"
				if defined($hash) || defined($passphrase);
			$self->_passphrase_acceptable($value)
				or croak "can't accept a passphrase exceeding".
						" fourteen bytes";
			$passphrase = $value;
		} else {
			croak "unrecognised attribute `$attr'";
		}
	}
	if(defined $passphrase) {
		$self->{first_half} =
			Authen::Passphrase::LANManagerHalf
				->new(passphrase => substr($passphrase, 0, 7));
		$self->{second_half} =
			Authen::Passphrase::LANManagerHalf
				->new(passphrase =>
					length($passphrase) > 7 ?
						substr($passphrase, 7, 7) :
						"");
	} elsif(defined $hash) {
		$self->{first_half} = Authen::Passphrase::LANManagerHalf
					->new(hash => substr($hash, 0, 8));
		$self->{second_half} = Authen::Passphrase::LANManagerHalf
					->new(hash => substr($hash, 8, 8));
	} else {
		croak "hash not specified";
	}
	return $self;
}

=item Authen::Passphrase::LANManager->from_rfc2307(USERPASSWORD)

Generates a LAN Manager passphrase recogniser from the supplied RFC2307
encoding.  The string must consist of "B<{LANMAN}>" (or its synonym
"B<{LANM}>") followed by the hash in hexadecimal; case is ignored.

=cut

sub from_rfc2307 {
	my($class, $userpassword) = @_;
	if($userpassword =~ /\A\{(?i:lanm(?:an)?)\}/) {
		$userpassword =~ /\A\{.*?\}([0-9a-fA-F]{32})\z/
			or croak "malformed {LANMAN} data";
		my $hash = $1;
		return $class->new(hash_hex => $hash);
	}
	return $class->SUPER::from_rfc2307($userpassword);
}

=back

=head1 METHODS

=over

=item $ppr->hash

Returns the hash value, as a string of 16 bytes.

=cut

sub hash {
	my($self) = @_;
	return $self->{first_half}->hash.$self->{second_half}->hash;
}

=item $ppr->hash_hex

Returns the hash value, as a string of 32 hexadecimal digits.

=cut

sub hash_hex {
	my($self) = @_;
	return unpack("H*", $self->hash);
}

=item $ppr->first_half

Returns the hash of the first half of the passphrase, as an
L<Authen::Passphrase::LANManagerHalf> passphrase recogniser.

=cut

sub first_half {
	my($self) = @_;
	return $self->{first_half};
}

=item $ppr->second_half

Returns the hash of the second half of the passphrase, as an
L<Authen::Passphrase::LANManagerHalf> passphrase recogniser.

=cut

sub second_half {
	my($self) = @_;
	return $self->{second_half};
}

=item $ppr->match(PASSPHRASE)

=item $ppr->as_rfc2307

These methods are part of the standard L<Authen::Passphrase> interface.



( run in 2.402 seconds using v1.01-cache-2.11-cpan-364913b4093 )