mdo and save/store writed

This commit is contained in:
Difrex(Denis Zheleztsov) 2014-04-29 11:37:41 +04:00
parent 7552e70081
commit 085d0a7222
3 changed files with 44 additions and 5 deletions

View File

@ -51,7 +51,7 @@ sub mdo {
return $q_hash; return $q_hash;
} }
elsif ( $type eq 'do' ) { elsif ( $type eq 'do' ) {
$dbh->do($q); $dbh->do($q) or die "$!\n";
return 0; return 0;
} }
else { else {

View File

@ -22,8 +22,6 @@ sub new {
my $self = { my $self = {
_db => $db, _db => $db,
_gpg => $gpg, _gpg => $gpg,
_p_save => $p_save,
_p_show => $p_show,
}; };
bless $self, $class; bless $self, $class;
@ -57,6 +55,47 @@ sub show {
return $q_hash; 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. # Check configuration. If it doesn't exist create it.
sub check_config { sub check_config {
my ($self) = @_; my ($self) = @_;

4
pm.pl
View File

@ -3,7 +3,7 @@
use Password; use Password;
use Getopt::Std; use Getopt::Std;
our $VERSION = '0.0.0d'; our $VERSION = '0.0.1a';
# Debug # Debug
use Data::Dumper; use Data::Dumper;
@ -45,7 +45,7 @@ EOF
sub init() { sub init() {
my $opt_string = 'swn:l:p:rhv'; my $opt_string = 'swn:l:p:rhv';
getopts("$opt_string") or usage(); 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: " print "Simple password manager writed in Perl.\nVersion: "
. $VERSION . $VERSION