pass length + db import

This commit is contained in:
vit 2016-05-01 21:27:28 +08:00
parent c2a9ab5041
commit b12748e25f
5 changed files with 43 additions and 9 deletions

18
GPG.pm
View File

@ -77,7 +77,7 @@ sub decrypt_db {
my @chars = ( "A" .. "Z", "a" .. "z" ); my @chars = ( "A" .. "Z", "a" .. "z" );
my $string; my $string;
$string .= $chars[ rand @chars ] for 1 .. 10; $string .= $chars[ rand @chars ] for 1 .. 10;
my $file = '/tmp/' . 'pm.' . $string; my $file = '/dev/shm/' . 'pm.' . $string;
# gpg --output /tmp/decryptfile --decrypt $db # gpg --output /tmp/decryptfile --decrypt $db
@dec_cmd = ( "$gpg", "--output", "$file", "--decrypt", "$db" ); @dec_cmd = ( "$gpg", "--output", "$file", "--decrypt", "$db" );
@ -109,4 +109,18 @@ sub export {
return $export_file; 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;

View File

@ -110,6 +110,13 @@ sub export {
return 0; return 0;
} }
sub import_db {
my ( $self, $filename ) = @_;
my $gpg = $self->{_gpg};
return $gpg->import_db($filename);
}
# Decrypt base and store new password # Decrypt base and store new password
sub save { sub save {
my ( $self, $store ) = @_; my ( $self, $store ) = @_;
@ -153,10 +160,14 @@ sub save {
# Generate password # Generate password
sub generate { sub generate {
my ($self, $length) = @_;
my $value; my $value;
# Defaults # Defaults
my $length = 16; if (!$length) {
$length = 16;
}
my $digest; my $digest;
for (1..32) { for (1..32) {

View File

@ -84,6 +84,4 @@ Show help screen:
# TODO # TODO
* Import/Export with simple(only password) encryption * Store decrypted DB into RAM not in /tmp/
* Password lenght
* Store decrypted DB into RAM not in /tmp/

View File

@ -21,11 +21,13 @@ Simple password manager writed in Perl.
-c comment -c comment
-p [Password] password -p [Password] password
if key not selected PM generate secure password if key not selected PM generate secure password
-e [number] (with length [number] if mentioned)
and copy it to xclipboard and copy it to xclipboard
-r remove password -r remove password
-i password ID -i password ID
-o open link -o open link
-x [filename] export -x [filename] export
-b [filename] import database
-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

15
pm.pl
View File

@ -15,11 +15,12 @@ our $VERSION = '0.0.1';
my $usage = Usage->new(); my $usage = Usage->new();
sub init() { 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(); getopts("$opt_string") or $usage->show();
our ( our (
$opt_s, $opt_w, $opt_n, $opt_r, $opt_l, $opt_p, $opt_h, $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_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: " print "Simple password manager writed in Perl.\nVersion: "
@ -107,7 +108,11 @@ elsif ( defined($opt_w)
# Generate password and store it into DB # Generate password and store it into DB
$opt_g = '' if !($opt_g); $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 = { my $store_h = {
name => $opt_n, name => $opt_n,
@ -149,6 +154,10 @@ elsif ( defined($opt_x) ) {
$pass->export($opt_x); $pass->export($opt_x);
print colored( "Dabase stored in $opt_x\n", 'green' ); 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 { else {
$usage->show(); $usage->show();
} }