App-Raps2

 view release on metacpan or  search on metacpan

SIGNATURE  view on Meta::CPAN

This file contains message digests of all files listed in MANIFEST,
signed via the Module::Signature module, version 0.79.

To verify the content in this distribution, first make sure you have
Module::Signature installed, then type:

    % cpansign -v

It will check each file's integrity, as well as the signature's
validity.  If "==> Signature verified OK! <==" is not displayed,
the distribution may already have been compromised, and you should
not run its Makefile.PL or Build.PL.

-----BEGIN PGP SIGNED MESSAGE-----

lib/App/Raps2.pm  view on Meta::CPAN

	if ( not defined $pass ) {
		$pass = $self->ui->read_pw( 'Master Password', 0 );
	}

	$self->{pass} = App::Raps2::Password->new(
		cost       => $self->{master_cost},
		salt       => $self->{master_salt},
		passphrase => $pass,
	);

	$self->pw->verify( $self->{master_hash} );

	return;
}

sub create_config {
	my ($self) = @_;

	my $cost = $self->{master_cost} = $self->{default}{cost} // 12;

	my $pass = $self->{default}{master_password} // $self->ui->read_pw(

lib/App/Raps2/Password.pm  view on Meta::CPAN

			{
				key_nul => 1,
				cost    => $self->{cost},
				salt    => $self->{salt},
			},
			$self->{passphrase},
		)
	);
}

sub verify {
	my ( $self, $testhash ) = @_;

	my $myhash = $self->bcrypt();

	if ( $testhash eq $myhash ) {
		return 1;
	}
	confess('Passwords did not match');
}

lib/App/Raps2/Password.pm  view on Meta::CPAN


=head1 SYNOPSIS

    use App::Raps2::Password;

    my $pass = App::Raps2::Password->new(
        passphrase => 'secret',
    );

    my $oneway_hash = $raps2->bcrypt();
    $raps2->verify($oneway_hash);

    my $twoway_hash = $raps2->encrypt('data');
    print $raps2->decrypt($twoway_hash);
    # "data"

=head1 VERSION

This manual documents B<App::Raps2::Password> version 0.54

=head1 DESCRIPTION

lib/App/Raps2/Password.pm  view on Meta::CPAN


Decrypts I<hexstr> (as created by B<encrypt>), returns its original content.

By default, the salt set in B<salt> or B<new> will be used. You can override
it by specifying I<salt>.

=item $pass->bcrypt()

Return a base64 bcrypt hash of the password, salted with the salt.

=item $pass->verify(I<hash>)

Verify a hash as returned by B<crypt>.

Returns true if it matches, dies if it doesn't.

=back

=head1 DIAGNOSTICS

When anything goes wrong, App::Raps2::Password will use Carp(3pm)'s B<confess>

lib/App/Raps2/UI.pm  view on Meta::CPAN

	say "${str} (^D or empty line to quit)";

	while ( my $line = $self->read_line('multiline') ) {
		$in .= "${line}\n";
	}

	return $in;
}

sub read_pw {
	my ( $self, $str, $verify ) = @_;

	my ( $in1, $in2 );
	my $term = POSIX::Termios->new();

	$term->getattr(0);
	$term->setlflag( $term->getlflag() & ~POSIX::ECHO );
	$term->setattr( 0, POSIX::TCSANOW );

	print "${str}: ";
	$in1 = readline(STDIN);
	print "\n";

	if ($verify) {
		print 'Verify: ';
		$in2 = readline(STDIN);
		print "\n";
	}

	$term->setlflag( $term->getlflag() | POSIX::ECHO );
	$term->setattr( 0, POSIX::TCSANOW );

	if ( $verify and $in1 ne $in2 ) {
		confess('Input lines did not match');
	}

	chomp $in1;

	return $in1;
}

sub to_clipboard {
	my ( $self, $str, $cmd ) = @_;

lib/App/Raps2/UI.pm  view on Meta::CPAN

by a newline.  I<prefill> sets the default content of the answer field.

Returns the user's reply, excluding the newline.

=item $ui->read_multiline(I<$message>)

Like B<read_line>, but repeats I<message> each time the user hits return.
Input is terminated by EOF (Ctrl+D).  Returns a string concatenation of all
lines (including newlines).

=item $ui->read_pw(I<$message>, I<$verify>)

Prompt the user for a password. I<message> is displayed, the user's input is
noch echoed.  If I<verify> is set, the user has to enter the same input twice,
otherwise B<read_pw> dies.  Returns the input.

=item $ui->to_clipboard(I<$string>, [I<command>])

Call I<command> to place I<string> in the primary X Clipboard.  I<command>
defaults to C<< xclip -l 1 >>.

Returns true upon success, undef if the operation failed. Use $! to get the
error message.

t/20-app-raps2-password.t  view on Meta::CPAN

	passphrase => $pass,
);

isa_ok($pw, 'App::Raps2::Password');

is($pw->decrypt(data => '53616c7465645f5f80d8c367e15980d43ec9a6eabc5390b4'), 'quux',
	'decrypt okay');

is($pw->decrypt(data => $pw->encrypt(data => 'foo')), 'foo', 'encrypt->decrypt okay');

ok($pw->verify('3lJRlaRuOGWv/z3g1DAOlcH.u9vS8Wm'), 'verify: verifies correct hash');

like(
	exception {
		$pw->verify('3lJRlaRuOGWv/z3g1DAOlcH.u9vS8WM');
	},
	qr{Passwords did not match},
	'verify: does not verify invalid hash'
);

ok($pw->verify($pw->bcrypt('truth')), 'bcrypt->verify okay');

is($pw->salt(), $salt, 'salt() returns current salt');

like(
	exception {
		$pw->salt('');
	},
	qr{incorrect salt length},
	'salt: Empty argument',
);



( run in 0.251 second using v1.01-cache-2.11-cpan-73692580452 )