pass length + db import
This commit is contained in:
parent
c2a9ab5041
commit
b12748e25f
18
GPG.pm
18
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;
|
13
Password.pm
13
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) {
|
||||
|
@ -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/
|
2
Usage.pm
2
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
|
||||
|
||||
|
15
pm.pl
15
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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user