From b12748e25f6bd262002ec6f93f1d1d7095a85b18 Mon Sep 17 00:00:00 2001 From: vit Date: Sun, 1 May 2016 21:27:28 +0800 Subject: [PATCH 1/2] pass length + db import --- GPG.pm | 18 ++++++++++++++++-- Password.pm | 13 ++++++++++++- README.md | 4 +--- Usage.pm | 2 ++ pm.pl | 15 ++++++++++++--- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/GPG.pm b/GPG.pm index 88ecc5f..fd59043 100644 --- a/GPG.pm +++ b/GPG.pm @@ -77,7 +77,7 @@ sub decrypt_db { my @chars = ( "A" .. "Z", "a" .. "z" ); my $string; $string .= $chars[ rand @chars ] for 1 .. 10; - my $file = '/tmp/' . 'pm.' . $string; + my $file = '/dev/shm/' . 'pm.' . $string; # gpg --output /tmp/decryptfile --decrypt $db @dec_cmd = ( "$gpg", "--output", "$file", "--decrypt", "$db" ); @@ -109,4 +109,18 @@ sub export { return $export_file; } -1; +sub import_db { + my ($self, $file) = @_; + + my @chars = ( "A" .. "Z", "a" .. "z" ); + my $string; + + $string .= $chars[ rand @chars ] for 1 .. 10; + my $tmpfile = '/dev/shm/' . 'pm.' . $string; + + system("gpg --output $tmpfile --decrypt $file") == 0 or die "Cannot decrypt $file: $!\n"; + my $encrypted = $self->encrypt_db($tmpfile); + return $encrypted; +} + +1; \ No newline at end of file diff --git a/Password.pm b/Password.pm index 1e8e36d..7fe42e1 100644 --- a/Password.pm +++ b/Password.pm @@ -110,6 +110,13 @@ sub export { return 0; } +sub import_db { + my ( $self, $filename ) = @_; + my $gpg = $self->{_gpg}; + + return $gpg->import_db($filename); +} + # Decrypt base and store new password sub save { my ( $self, $store ) = @_; @@ -153,10 +160,14 @@ sub save { # Generate password sub generate { + my ($self, $length) = @_; + my $value; # Defaults - my $length = 16; + if (!$length) { + $length = 16; + } my $digest; for (1..32) { diff --git a/README.md b/README.md index 7db6a5a..c59c22c 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,4 @@ Show help screen: # TODO -* Import/Export with simple(only password) encryption -* Password lenght -* Store decrypted DB into RAM not in /tmp/ +* Store decrypted DB into RAM not in /tmp/ \ No newline at end of file diff --git a/Usage.pm b/Usage.pm index 616336b..1203192 100644 --- a/Usage.pm +++ b/Usage.pm @@ -21,11 +21,13 @@ Simple password manager writed in Perl. -c comment -p [Password] password if key not selected PM generate secure password + -e [number] (with length [number] if mentioned) and copy it to xclipboard -r remove password -i password ID -o open link -x [filename] export + -b [filename] import database -h show this help screen and exit -v show version info and exit diff --git a/pm.pl b/pm.pl index 3753b44..df763ed 100755 --- a/pm.pl +++ b/pm.pl @@ -15,11 +15,12 @@ our $VERSION = '0.0.1'; my $usage = Usage->new(); sub init() { - my $opt_string = 'swn:l:p:rhvou:i:c:x:g:'; + my $opt_string = 'swn:l:p:rhvou:i:c:x:g:b:e:'; 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_c, $opt_x, $opt_g, + $opt_b, $opt_e ); print "Simple password manager writed in Perl.\nVersion: " @@ -107,7 +108,11 @@ elsif ( defined($opt_w) # Generate password and store it into DB $opt_g = '' if !($opt_g); - $opt_p = $pass->generate(); + if ( defined($opt_e) ) { + $pass_length=$opt_e; + } + + $opt_p = $pass->generate($pass_length); my $store_h = { name => $opt_n, @@ -149,6 +154,10 @@ elsif ( defined($opt_x) ) { $pass->export($opt_x); print colored( "Dabase stored in $opt_x\n", 'green' ); } +elsif ( defined($opt_b) ) { + $pass->import_db($opt_b); + print colored( "Database imported from $opt_b\n", 'green' ); +} else { $usage->show(); -} +} \ No newline at end of file From a9443b4a4e1614bc64248e810101c6218c85eb0c Mon Sep 17 00:00:00 2001 From: "Viktor (vit01)" Date: Wed, 4 May 2016 19:43:28 +0900 Subject: [PATCH 2/2] Update AUTHORS --- AUTHORS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AUTHORS b/AUTHORS index 2789be8..069ea40 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,7 @@ Denis a.k.a Difrex Zheleztsov mailto://difrex.punk@gmail.com/ copyleft 2014 + +Viktor (vit01, vit1-irk) Fedenyov +mailto://me@ii-net.tk +copyleft 2016