Username select is working
This commit is contained in:
parent
287ac09440
commit
16b5c2d680
21
Password.pm
21
Password.pm
@ -26,7 +26,7 @@ sub new {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub show {
|
sub show {
|
||||||
my ( $self, $name ) = @_;
|
my ( $self, $name, $username ) = @_;
|
||||||
my $db_class = $self->{_db};
|
my $db_class = $self->{_db};
|
||||||
my $gpg = $self->{_gpg};
|
my $gpg = $self->{_gpg};
|
||||||
|
|
||||||
@ -34,8 +34,15 @@ sub show {
|
|||||||
my $dec_db_file = $gpg->decrypt_db();
|
my $dec_db_file = $gpg->decrypt_db();
|
||||||
|
|
||||||
# Query
|
# Query
|
||||||
my $query_string
|
my $query_string;
|
||||||
|
if ( defined($username) ) {
|
||||||
|
$query_string = "select name, resource, password from passwords
|
||||||
|
where name='$name' and username='$username'";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$query_string
|
||||||
= "select name, resource, password from passwords where name='$name'";
|
= "select name, resource, password from passwords where name='$name'";
|
||||||
|
}
|
||||||
|
|
||||||
my $mdo_q = {
|
my $mdo_q = {
|
||||||
file => $dec_db_file,
|
file => $dec_db_file,
|
||||||
@ -62,7 +69,12 @@ sub save {
|
|||||||
my $resource = $store->{resource};
|
my $resource = $store->{resource};
|
||||||
my $password = $store->{password};
|
my $password = $store->{password};
|
||||||
my $generate = $store->{gen};
|
my $generate = $store->{gen};
|
||||||
my $username = defined($store->{username}) ? '' : '';
|
|
||||||
|
# Username check
|
||||||
|
my $username = '';
|
||||||
|
if (defined($store->{username})) {
|
||||||
|
$username = $store->{username}
|
||||||
|
}
|
||||||
|
|
||||||
if ( $generate == 1 ) {
|
if ( $generate == 1 ) {
|
||||||
$password = Password->generate();
|
$password = Password->generate();
|
||||||
@ -70,8 +82,7 @@ sub save {
|
|||||||
|
|
||||||
# Decrypt database
|
# Decrypt database
|
||||||
my $dec_db_file = $gpg->decrypt_db();
|
my $dec_db_file = $gpg->decrypt_db();
|
||||||
my $q
|
my $q = "insert into passwords(name, resource, password, username)
|
||||||
= "insert into passwords(name, resource, password, username)
|
|
||||||
values('$name', '$resource', '$password', '$username')";
|
values('$name', '$resource', '$password', '$username')";
|
||||||
my $mdo_q = {
|
my $mdo_q = {
|
||||||
file => $dec_db_file,
|
file => $dec_db_file,
|
||||||
|
17
pm.pl
17
pm.pl
@ -7,7 +7,7 @@ use ClipPass;
|
|||||||
# Debug
|
# Debug
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
our $VERSION = '0.0.1-alpha';
|
our $VERSION = '0.0.1-beta1';
|
||||||
|
|
||||||
sub usage() {
|
sub usage() {
|
||||||
print STDERR << "EOF";
|
print STDERR << "EOF";
|
||||||
@ -45,7 +45,7 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub init() {
|
sub init() {
|
||||||
my $opt_string = 'swn:l:p:rhvou';
|
my $opt_string = 'swn:l:p:rhvou:';
|
||||||
getopts("$opt_string") or usage();
|
getopts("$opt_string") or usage();
|
||||||
our (
|
our (
|
||||||
$opt_s, $opt_w, $opt_n, $opt_r, $opt_l,
|
$opt_s, $opt_w, $opt_n, $opt_r, $opt_l,
|
||||||
@ -73,20 +73,21 @@ my $copy = ClipPass->new();
|
|||||||
# It's really ugly code. Sorry :(
|
# It's really ugly code. Sorry :(
|
||||||
if ( defined($opt_s) and defined($opt_n) and !defined($opt_o) ) {
|
if ( defined($opt_s) and defined($opt_n) and !defined($opt_o) ) {
|
||||||
|
|
||||||
my $get_h = $pass->show($opt_n);
|
my $get_h = $pass->show($opt_n, $opt_u);
|
||||||
my $get_pass = $get_h->{password};
|
my $get_pass = $get_h->{password};
|
||||||
|
|
||||||
$copy->copy($get_pass);
|
$copy->copy($get_pass);
|
||||||
|
|
||||||
print "Password copied to xclipboard.\nURI is " . $get_h->{resource} . "\n";
|
print "Password copied to xclipboard.\nURI is "
|
||||||
|
. $get_h->{resource} . "\n";
|
||||||
}
|
}
|
||||||
elsif ( defined($opt_s) and defined($opt_n) and defined($opt_o) ) {
|
elsif ( defined($opt_s) and defined($opt_n) and defined($opt_o) ) {
|
||||||
|
|
||||||
my $get_h = $pass->show($opt_n);
|
my $get_h = $pass->show($opt_n, $opt_u);
|
||||||
$copy->copy($get_h->{password});
|
$copy->copy( $get_h->{password} );
|
||||||
|
|
||||||
# Open resource.
|
# Open resource.
|
||||||
my @open_cmd = ('xdg-open', $get_h->{resource});
|
my @open_cmd = ( 'xdg-open', $get_h->{resource} );
|
||||||
system(@open_cmd) == 0 or die "Cannot open URI: $!\n";
|
system(@open_cmd) == 0 or die "Cannot open URI: $!\n";
|
||||||
|
|
||||||
print "Password copied to clipboard. Trying to open uri.\n";
|
print "Password copied to clipboard. Trying to open uri.\n";
|
||||||
@ -103,6 +104,7 @@ elsif ( defined($opt_w)
|
|||||||
name => $opt_n,
|
name => $opt_n,
|
||||||
resource => $opt_l,
|
resource => $opt_l,
|
||||||
gen => 1,
|
gen => 1,
|
||||||
|
username => $opt_u,
|
||||||
};
|
};
|
||||||
|
|
||||||
$pass->save($store_h) == 0 or die "Oops! 105: pm.pl. $!\n";
|
$pass->save($store_h) == 0 or die "Oops! 105: pm.pl. $!\n";
|
||||||
@ -120,6 +122,7 @@ elsif ( defined($opt_w)
|
|||||||
resource => $opt_l,
|
resource => $opt_l,
|
||||||
password => $opt_p,
|
password => $opt_p,
|
||||||
gen => 0,
|
gen => 0,
|
||||||
|
username => $opt_u,
|
||||||
};
|
};
|
||||||
|
|
||||||
$pass->save($store_h) == 0 or die "Oops! 122: pm.pl. $!\n";
|
$pass->save($store_h) == 0 or die "Oops! 122: pm.pl. $!\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user