mdo and save/store writed
This commit is contained in:
parent
7552e70081
commit
085d0a7222
@ -51,7 +51,7 @@ sub mdo {
|
||||
return $q_hash;
|
||||
}
|
||||
elsif ( $type eq 'do' ) {
|
||||
$dbh->do($q);
|
||||
$dbh->do($q) or die "$!\n";
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
|
43
Password.pm
43
Password.pm
@ -22,8 +22,6 @@ sub new {
|
||||
my $self = {
|
||||
_db => $db,
|
||||
_gpg => $gpg,
|
||||
_p_save => $p_save,
|
||||
_p_show => $p_show,
|
||||
};
|
||||
|
||||
bless $self, $class;
|
||||
@ -57,6 +55,47 @@ sub show {
|
||||
return $q_hash;
|
||||
}
|
||||
|
||||
# Decrypt base and store new password
|
||||
sub save {
|
||||
my ( $self, $store ) = @_;
|
||||
my $db_class = $self->{_db};
|
||||
my $gpg = $self->{_gpg};
|
||||
|
||||
my $name = $store->{name};
|
||||
my $resource = $store->{resource};
|
||||
my $password = $store->{password};
|
||||
my $generate = $store->{gen};
|
||||
|
||||
if ( $generate == 1 ) {
|
||||
$password = Password->generate();
|
||||
}
|
||||
|
||||
# Decrypt database
|
||||
my $dec_db_file = $gpg->decrypt_db();
|
||||
my $q
|
||||
= "insert into passwords(name, resource, password) values($name, $resource, $password)";
|
||||
my $mdo_q = {
|
||||
file => $dec_db_file,
|
||||
name => $name,
|
||||
query => $query,
|
||||
type => 'do',
|
||||
};
|
||||
|
||||
$db_class->mdo($mdo_q);
|
||||
$gpg->encrypt_db($dec_db_file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
# Generate password
|
||||
sub generate {
|
||||
my @chars = ( "A" .. "Z", "a" .. "z", 0 .. 9 );
|
||||
my $string;
|
||||
$string .= $chars[ rand @chars ] for 1 .. 16;
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
# Check configuration. If it doesn't exist create it.
|
||||
sub check_config {
|
||||
my ($self) = @_;
|
||||
|
4
pm.pl
4
pm.pl
@ -3,7 +3,7 @@
|
||||
use Password;
|
||||
use Getopt::Std;
|
||||
|
||||
our $VERSION = '0.0.0d';
|
||||
our $VERSION = '0.0.1a';
|
||||
|
||||
# Debug
|
||||
use Data::Dumper;
|
||||
@ -45,7 +45,7 @@ EOF
|
||||
sub init() {
|
||||
my $opt_string = 'swn:l:p:rhv';
|
||||
getopts("$opt_string") or usage();
|
||||
our ( $opt_s, $opt_w, $opt_n, $opt_r, $opt_l, $opt_p, $opt_h, $opt_v );
|
||||
our ( $opt_s, $opt_w, $opt_n, $opt_r, $opt_l, $opt_p, $opt_h, $opt_v, $opt_o );
|
||||
|
||||
print "Simple password manager writed in Perl.\nVersion: "
|
||||
. $VERSION
|
||||
|
Loading…
Reference in New Issue
Block a user