diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-05-17 14:42:25 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-05-17 14:42:25 +0200 |
commit | 9f84c2ba374a07fcf12fdf41c0d6f1fc3f315655 (patch) | |
tree | 04e499e55236909676318be4ca69286fb6ada9bd /lib/App/Raps2 | |
parent | 391929448038a478f23cfa28db528e1f4a1e60d9 (diff) |
Move create_salt to App::Raps2::Password, make $pw->salt() return current salt
Diffstat (limited to 'lib/App/Raps2')
-rw-r--r-- | lib/App/Raps2/Password.pm | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/App/Raps2/Password.pm b/lib/App/Raps2/Password.pm index 10431ed..b236b7b 100644 --- a/lib/App/Raps2/Password.pm +++ b/lib/App/Raps2/Password.pm @@ -17,6 +17,10 @@ sub new { $conf{cost} //= 12; + if (not defined $conf{salt}) { + $conf{salt} = create_salt(); + } + if (not (defined $conf{salt} and length($conf{salt}) == 16)) { confess('incorrect salt length'); } @@ -30,9 +34,24 @@ sub new { return bless($ref, $obj); } +sub create_salt { + my ($self) = @_; + my $salt = q{}; + + for (1 .. 16) { + $salt .= chr(0x21 + int(rand(90))); + } + + return $salt; +} + sub salt { my ($self, $salt) = @_; + if (not defined $salt) { + return $self->{salt}; + } + if (not (defined $salt and length($salt) == 16)) { confess('incorrect salt length'); } |