bump version, add password retry 5 tries

This commit is contained in:
git@daemon.de
2015-06-03 09:31:03 +02:00
parent e3b179441f
commit f3983b0b7c
3 changed files with 43 additions and 20 deletions

View File

@@ -1,4 +1,6 @@
NEXT: fixed bug in mysql backend.
1.3.22: fixed bug in mysql backend.
added retry feature for NOTEDB::pwsafe3 backend save() password
entering. bails out after 5 retries.
================================================================================
1.3.21:
Changed note id generation in NOTEDB::pwsafe3::_uuid(), again.

View File

@@ -10,7 +10,7 @@ package NOTEDB;
use Exporter ();
use vars qw(@ISA @EXPORT $crypt_supported);
$NOTEDB::VERSION = "1.43";
$NOTEDB::VERSION = "1.44";
BEGIN {
# make sure, it works, otherwise encryption

View File

@@ -3,7 +3,7 @@
package NOTEDB::pwsafe3;
$NOTEDB::pwsafe3::VERSION = "1.07";
$NOTEDB::pwsafe3::VERSION = "1.08";
use strict;
use Data::Dumper;
use Time::Local;
@@ -281,30 +281,51 @@ sub _store {
flock $fh, LOCK_EX;
}
my $key = $this->_getpass();
eval {
my $vault = new Crypt::PWSafe3(password => $key, file => $this->{dbname});
if ($create) {
my $rec = new Crypt::PWSafe3::Record();
$rec->uuid($record->{uuid});
$vault->addrecord($rec);
$vault->modifyrecord($record->{uuid}, %{$record});
my $key;
my $prompt = "pwsafe password: ";
foreach my $try (1..5) {
if($try > 1) {
$prompt = "pwsafe password ($try retry): ";
}
$key = $this->_getpass($prompt);
eval {
my $vault = new Crypt::PWSafe3(password => $key, file => $this->{dbname});
if ($create) {
my $rec = new Crypt::PWSafe3::Record();
$rec->uuid($record->{uuid});
$vault->addrecord($rec);
$vault->modifyrecord($record->{uuid}, %{$record});
}
else {
$vault->modifyrecord($record->{uuid}, %{$record});
}
$vault->save();
};
if ($@) {
if($@ =~ /wrong pass/i) {
$key = '';
next;
}
else {
print "Exception caught:\n$@\n";
exit 1;
}
}
else {
$vault->modifyrecord($record->{uuid}, %{$record});
last;
}
$vault->save();
};
if ($@) {
print "Exception caught:\n$@\n";
exit 1;
}
eval {
flock $fh, LOCK_UN;
$fh->close();
};
if(!$key) {
print STDERR "Giving up after 5 failed password attempts.\n";
exit 1;
}
# finally re-read the db, so that we always have the latest data
$this->_retrieve($key);
}
@@ -483,14 +504,14 @@ sub _getpass {
# Instead we ask for the password everytime we want
# to fetch data from the actual file OR want to write
# to it. To minimize reads, we use caching by default.
my($this) = @_;
my($this, $prompt) = @_;
if ($this->{key}) {
return $this->{key};
}
else {
my $key;
print STDERR "pwsafe password: ";
print STDERR $prompt ? $prompt : "pwsafe password: ";
eval {
local($|) = 1;
local(*TTY);