Remove password is working
This commit is contained in:
parent
8e0f5ca987
commit
6aff364cbb
15
Database.pm
15
Database.pm
@ -44,19 +44,19 @@ sub mdo {
|
|||||||
|
|
||||||
# Bad hack
|
# Bad hack
|
||||||
if ( $name eq 'all' ) {
|
if ( $name eq 'all' ) {
|
||||||
my $q = 'select name, resource, username from passwords';
|
my $q = 'select id, name, resource, username from passwords';
|
||||||
|
|
||||||
my $sth = $dbh->prepare($q);
|
my $sth = $dbh->prepare($q);
|
||||||
my $rv = $sth->execute();
|
my $rv = $sth->execute();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
printf "%-11s %-11s %-11s\n", "NAME", "RESOURCE", "USERNAME";
|
printf "%-11s %-11s %-11s %-11s\n", "ID", "NAME", "RESOURCE", "USERNAME";
|
||||||
while ( my ( $name, $resource, $username )
|
while ( my ( $id, $name, $resource, $username )
|
||||||
= $sth->fetchrow_array() )
|
= $sth->fetchrow_array() )
|
||||||
{
|
{
|
||||||
printf "%-11s %-11s %-11s\n",
|
printf "%-11s %-11s %-11s %-11s\n",
|
||||||
$name, $resource, "\t$username";
|
$id, $name, $resource, $username;
|
||||||
}
|
}
|
||||||
# Remove unencrypted file
|
# Remove unencrypted file
|
||||||
my @rm_cmd = ( "rm", "-f", "$db_file" );
|
my @rm_cmd = ( "rm", "-f", "$db_file" );
|
||||||
@ -67,9 +67,10 @@ sub mdo {
|
|||||||
my $sth = $dbh->prepare($q);
|
my $sth = $dbh->prepare($q);
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
|
|
||||||
my ( $name, $resource, $password ) = $sth->fetchrow_array();
|
my ( $id, $name, $resource, $password ) = $sth->fetchrow_array();
|
||||||
|
|
||||||
my $q_hash = {
|
my $q_hash = {
|
||||||
|
id => $id,
|
||||||
name => $name,
|
name => $name,
|
||||||
resource => $resource,
|
resource => $resource,
|
||||||
password => $password,
|
password => $password,
|
||||||
@ -122,7 +123,7 @@ sub create_base {
|
|||||||
print "Create database schema\n";
|
print "Create database schema\n";
|
||||||
my $q_table
|
my $q_table
|
||||||
= "create table passwords(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(32), username VARCHAR(32),
|
= "create table passwords(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(32), username VARCHAR(32),
|
||||||
resource TEXT, password TEXT)";
|
resource TEXT, password TEXT, comment TEXT)";
|
||||||
$dbh->do($q_table);
|
$dbh->do($q_table);
|
||||||
|
|
||||||
print "Encrypt database...\n";
|
print "Encrypt database...\n";
|
||||||
|
26
Password.pm
26
Password.pm
@ -59,6 +59,28 @@ sub show {
|
|||||||
return $q_hash;
|
return $q_hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Remove password
|
||||||
|
sub remove {
|
||||||
|
my ( $self, $store ) = @_;
|
||||||
|
my $db_class = $self->{_db};
|
||||||
|
my $gpg = $self->{_gpg};
|
||||||
|
my $id = $store->{id};
|
||||||
|
|
||||||
|
# Decrypt database
|
||||||
|
my $dec_db_file = $gpg->decrypt_db();
|
||||||
|
my $q = "delete from passwords where id=$id";
|
||||||
|
my $mdo_q = {
|
||||||
|
file => $dec_db_file,
|
||||||
|
query => $q,
|
||||||
|
type => 'do',
|
||||||
|
};
|
||||||
|
|
||||||
|
$db_class->mdo($mdo_q);
|
||||||
|
$gpg->encrypt_db($dec_db_file);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
# Decrypt base and store new password
|
# Decrypt base and store new password
|
||||||
sub save {
|
sub save {
|
||||||
my ( $self, $store ) = @_;
|
my ( $self, $store ) = @_;
|
||||||
@ -72,8 +94,8 @@ sub save {
|
|||||||
|
|
||||||
# Username check
|
# Username check
|
||||||
my $username = '';
|
my $username = '';
|
||||||
if (defined($store->{username})) {
|
if ( defined( $store->{username} ) ) {
|
||||||
$username = $store->{username}
|
$username = $store->{username};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $generate == 1 ) {
|
if ( $generate == 1 ) {
|
||||||
|
19
pm.pl
19
pm.pl
@ -22,6 +22,7 @@ Simple password manager writed in Perl.
|
|||||||
if key not selected PM generate secure password
|
if key not selected PM generate secure password
|
||||||
and copy it to xclipboard
|
and copy it to xclipboard
|
||||||
-r remove password
|
-r remove password
|
||||||
|
-i password ID
|
||||||
-o open link
|
-o open link
|
||||||
-h show this help screen and exit
|
-h show this help screen and exit
|
||||||
-v show version info and exit
|
-v show version info and exit
|
||||||
@ -48,11 +49,11 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub init() {
|
sub init() {
|
||||||
my $opt_string = 'swn:l:p:rhvou:';
|
my $opt_string = 'swn:l:p:rhvou:i:';
|
||||||
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, $opt_p,
|
||||||
$opt_p, $opt_h, $opt_v, $opt_o, $opt_u
|
$opt_h, $opt_v, $opt_o, $opt_u, $opt_i,
|
||||||
);
|
);
|
||||||
|
|
||||||
print "Simple password manager writed in Perl.\nVersion: "
|
print "Simple password manager writed in Perl.\nVersion: "
|
||||||
@ -76,10 +77,11 @@ 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, $opt_u);
|
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);
|
||||||
|
|
||||||
# TEST
|
# TEST
|
||||||
use Term::ANSIColor;
|
use Term::ANSIColor;
|
||||||
print color 'green';
|
print color 'green';
|
||||||
@ -92,7 +94,7 @@ if ( defined($opt_s) and defined($opt_n) and !defined($opt_o) ) {
|
|||||||
}
|
}
|
||||||
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, $opt_u);
|
my $get_h = $pass->show( $opt_n, $opt_u );
|
||||||
$copy->copy( $get_h->{password} );
|
$copy->copy( $get_h->{password} );
|
||||||
|
|
||||||
# Open resource.
|
# Open resource.
|
||||||
@ -101,6 +103,13 @@ elsif ( defined($opt_s) and defined($opt_n) and defined($opt_o) ) {
|
|||||||
|
|
||||||
print "Password copied to clipboard. Trying to open uri.\n";
|
print "Password copied to clipboard. Trying to open uri.\n";
|
||||||
}
|
}
|
||||||
|
# Remove string from db
|
||||||
|
elsif ( defined($opt_r) and defined($opt_i) ) {
|
||||||
|
|
||||||
|
my $store_h = { id => $opt_i, };
|
||||||
|
|
||||||
|
$pass->remove($store_h) == 0 or die "Oops! 105: pm.pl. $!\n";
|
||||||
|
}
|
||||||
elsif ( defined($opt_w)
|
elsif ( defined($opt_w)
|
||||||
and defined($opt_n)
|
and defined($opt_n)
|
||||||
and defined($opt_l)
|
and defined($opt_l)
|
||||||
|
Loading…
Reference in New Issue
Block a user