Username select is working
This commit is contained in:
parent
287ac09440
commit
16b5c2d680
23
Password.pm
23
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;
|
||||||
= "select name, resource, password from passwords where name='$name'";
|
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'";
|
||||||
|
}
|
||||||
|
|
||||||
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,
|
||||||
|
51
pm.pl
51
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";
|
||||||
@ -28,24 +28,24 @@ Simple password manager writed in Perl.
|
|||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
Show password for resource:
|
Show password for resource:
|
||||||
\tpm.pl -s -n LOR
|
\tpm.pl -s -n LOR
|
||||||
\tPassword copied to xclipboard.\n\t\tURI is http://linux.org.ru/
|
\tPassword copied to xclipboard.\n\t\tURI is http://linux.org.ru/
|
||||||
|
|
||||||
Store new password:
|
Store new password:
|
||||||
\tpm.pl -w -n PRON -l http://superpronsite.com/ -p my_secret_password
|
\tpm.pl -w -n PRON -l http://superpronsite.com/ -p my_secret_password
|
||||||
\tPassword for resource PRON is stored into DB!
|
\tPassword for resource PRON is stored into DB!
|
||||||
|
|
||||||
Copy password and open link:
|
Copy password and open link:
|
||||||
\tpm.pl -s -n LOR -o
|
\tpm.pl -s -n LOR -o
|
||||||
\tPassword copied to clipboard. Trying to open uri.
|
\tPassword copied to clipboard. Trying to open uri.
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
@ -62,7 +62,7 @@ sub init() {
|
|||||||
my $pass = Password->new();
|
my $pass = Password->new();
|
||||||
|
|
||||||
if ( $pass->check_config() == 0 ) {
|
if ( $pass->check_config() == 0 ) {
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
@ -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";
|
||||||
@ -100,9 +101,10 @@ elsif ( defined($opt_w)
|
|||||||
print "$opt_w, $opt_n, $opt_l, $opt_p\n";
|
print "$opt_w, $opt_n, $opt_l, $opt_p\n";
|
||||||
|
|
||||||
my $store_h = {
|
my $store_h = {
|
||||||
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";
|
||||||
@ -116,10 +118,11 @@ elsif ( defined($opt_w)
|
|||||||
print "$opt_w, $opt_n, $opt_l, $opt_p\n";
|
print "$opt_w, $opt_n, $opt_l, $opt_p\n";
|
||||||
|
|
||||||
my $store_h = {
|
my $store_h = {
|
||||||
name => $opt_n,
|
name => $opt_n,
|
||||||
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