* passwords are now validated based on - minlen - maxlen - min lower case chars - min uppper case chars - min digits - min special chars * Data::Password::zxcvbn is used to calculate password score and reject passwords with score < 3 as weak (this library is ported from the Dropbox password validation) * Add password journals and check last used passwords in the journals * Improve password generator javascript function to generate a password with at least 4 of each of the char group types. * Currently affected are subcriber and admin entry creation or modification via UI/API * NGCP::Utils::Auth add optional bcrypt_cost support as last argument for generate_salted_hash and get_usr_salted_pass Change-Id: I100c25107d91741d5101bc58d29a3fa558b0b017mr12.5
parent
43d112bd5e
commit
d9f283cbc8
@ -0,0 +1,65 @@
|
|||||||
|
package NGCP::Panel::Utils::Admin;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use Sipwise::Base;
|
||||||
|
|
||||||
|
use NGCP::Panel::Utils::Generic qw(:all);
|
||||||
|
|
||||||
|
use DBIx::Class::Exception;
|
||||||
|
use NGCP::Panel::Utils::Auth;
|
||||||
|
|
||||||
|
use HTTP::Status qw(:constants);
|
||||||
|
|
||||||
|
sub insert_password_journal {
|
||||||
|
my ($c, $admin, $password) = @_;
|
||||||
|
|
||||||
|
my $bcrypt_cost = 6;
|
||||||
|
my $keep_last_used = $c->config->{security}{password}{web_keep_last_used} // return;
|
||||||
|
|
||||||
|
my $rs = $admin->last_passwords->search({
|
||||||
|
},{
|
||||||
|
order_by => { '-desc' => 'created_at' },
|
||||||
|
});
|
||||||
|
|
||||||
|
my @delete_ids = ();
|
||||||
|
my $idx = 0;
|
||||||
|
foreach my $row ($rs->all) {
|
||||||
|
$idx++;
|
||||||
|
$idx >= $keep_last_used ? push @delete_ids, $row->id : next;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $del_rs = $rs->search({
|
||||||
|
id => { -in => \@delete_ids },
|
||||||
|
});
|
||||||
|
|
||||||
|
$del_rs->delete;
|
||||||
|
|
||||||
|
$admin->last_passwords->create({
|
||||||
|
admin_id => $admin->id,
|
||||||
|
value => NGCP::Panel::Utils::Auth::generate_salted_hash($password, $bcrypt_cost),
|
||||||
|
});
|
||||||
|
$admin->update({ saltedpass_modify_timestamp => \'current_timestamp()' });
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
NGCP::Panel::Utils::Admin
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
A temporary helper to manipulate admin data
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
Sipwise Development Team <support@sipwise.com>
|
||||||
|
|
||||||
|
=head1 LICENSE
|
||||||
|
|
||||||
|
This library is free software. You can redistribute it and/or modify
|
||||||
|
it under the same terms as Perl itself.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
# vim: set tabstop=4 expandtab:
|
Loading…
Reference in new issue