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: 1.3.21:
Changed note id generation in NOTEDB::pwsafe3::_uuid(), again. Changed note id generation in NOTEDB::pwsafe3::_uuid(), again.

View File

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

View File

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