diff --git a/Database.pm b/Database.pm index d8651fa..16336b2 100644 --- a/Database.pm +++ b/Database.pm @@ -44,26 +44,32 @@ sub mdo { # Bad hack if ( $name eq 'all' ) { - my $q = 'select id, name, resource, username from passwords'; + my $q + = 'select id, name, resource, username, comment from passwords'; my $sth = $dbh->prepare($q); my $rv = $sth->execute(); use Term::ANSIColor; - printf "%-11s %-11s %-11s %-11s\n", + printf "%-11s %-11s %-11s %-11s %-11s\n", colored( "ID", 'white' ), colored( "NAME", 'magenta' ), colored( "RESOURCE", 'blue' ), - colored( "USERNAME", 'green' ); - print "=========================\n"; - while ( my ( $id, $name, $resource, $username ) + colored( "USERNAME", 'green' ), + colored( "COMMENT", 'yellow' ); + print "=================================\n"; + while ( my ( $id, $name, $resource, $username, $comment ) = $sth->fetchrow_array() ) { - printf "%-11s %-11s %-11s %-11s\n", + if ( !defined($comment) ) { + $comment = ''; + } + printf "%-11s %-11s %-11s %-11s %-11s\n", colored( $id, 'white' ), colored( $name, 'magenta' ), colored( $resource, 'blue' ), - colored( $username, 'green' ); + colored( $username, 'green' ), + colored( $comment, 'yellow' ); } # Remove unencrypted file diff --git a/Password.pm b/Password.pm index aa313a3..e2c12eb 100644 --- a/Password.pm +++ b/Password.pm @@ -68,8 +68,8 @@ sub remove { # Decrypt database my $dec_db_file = $gpg->decrypt_db(); - my $q = "delete from passwords where id=$id"; - my $mdo_q = { + my $q = "delete from passwords where id=$id"; + my $mdo_q = { file => $dec_db_file, query => $q, type => 'do', @@ -90,6 +90,12 @@ sub save { my $name = $store->{name}; my $resource = $store->{resource}; my $password = $store->{password}; + + # Comment check + my $comment = ''; + if ( defined( $store->{comment} ) ) { + $comment = $store->{comment}; + } # Username check my $username = ''; @@ -99,8 +105,8 @@ sub save { # Decrypt database my $dec_db_file = $gpg->decrypt_db(); - my $q = "insert into passwords(name, resource, password, username) - values('$name', '$resource', '$password', '$username')"; + my $q = "insert into passwords(name, resource, password, username, comment) + values('$name', '$resource', '$password', '$username', '$comment')"; my $mdo_q = { file => $dec_db_file, name => $name, diff --git a/Usage.pm b/Usage.pm index 2774a2f..f5efd61 100644 --- a/Usage.pm +++ b/Usage.pm @@ -17,6 +17,7 @@ Simple password manager writed in Perl. -w store new password -l [Link] link to resource -u username + -c comment -p [Password] password if key not selected PM generate secure password and copy it to xclipboard @@ -40,7 +41,7 @@ Examples: \tPassword copied to clipboard. Trying to open uri. 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 -c 'Most viewed site' \tPassword for resource PRON is stored into DB! Remove password: diff --git a/pm.pl b/pm.pl index bfe1a60..68cfa67 100755 --- a/pm.pl +++ b/pm.pl @@ -15,11 +15,11 @@ our $VERSION = '0.0.1-beta1'; my $usage = Usage->new(); sub init() { - my $opt_string = 'swn:l:p:rhvou:i:'; + my $opt_string = 'swn:l:p:rhvou:i:c:'; getopts("$opt_string") or $usage->show(); our ( $opt_s, $opt_w, $opt_n, $opt_r, $opt_l, $opt_p, - $opt_h, $opt_v, $opt_o, $opt_u, $opt_i, + $opt_h, $opt_v, $opt_o, $opt_u, $opt_i, $opt_c, ); print "Simple password manager writed in Perl.\nVersion: " @@ -73,6 +73,7 @@ elsif ( defined($opt_s) and defined($opt_n) and defined($opt_o) ) { print $get_h->{resource} . "\n"; print color 'reset'; } + # Remove string from db elsif ( defined($opt_r) and defined($opt_i) ) { @@ -98,10 +99,11 @@ elsif ( defined($opt_w) resource => $opt_l, password => $opt_p, username => $opt_u, + comment => $opt_c, }; $pass->save($store_h) == 0 or die "Oops! 105: pm.pl. $!\n"; - $copy->copy( $opt_p ); + $copy->copy($opt_p); print color 'green'; print "Password was stored into DB!\n"; print color 'reset'; @@ -120,6 +122,7 @@ elsif ( defined($opt_w) password => $opt_p, gen => 0, username => $opt_u, + comment => $opt_c, }; $pass->save($store_h) == 0 or die "Oops! 122: pm.pl. $!\n";