← Index
NYTProf Performance Profile   « line view »
For /usr/local/libexec/sympa/task_manager-debug.pl
  Run on Tue Jun 1 22:32:51 2021
Reported on Tue Jun 1 22:35:11 2021

Filename/usr/local/libexec/sympa/Sympa/Tools/Password.pm
StatementsExecuted 0 statements in 0s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
0000s0sSympa::Tools::Password::::BEGIN@30Sympa::Tools::Password::BEGIN@30
0000s0sSympa::Tools::Password::::BEGIN@31Sympa::Tools::Password::BEGIN@31
0000s0sSympa::Tools::Password::::BEGIN@32Sympa::Tools::Password::BEGIN@32
0000s0sSympa::Tools::Password::::BEGIN@33Sympa::Tools::Password::BEGIN@33
0000s0sSympa::Tools::Password::::BEGIN@35Sympa::Tools::Password::BEGIN@35
0000s0sSympa::Tools::Password::::BEGIN@36Sympa::Tools::Password::BEGIN@36
0000s0sSympa::Tools::Password::::__ANON__Sympa::Tools::Password::__ANON__ (xsub)
0000s0sSympa::Tools::Password::::get_randomSympa::Tools::Password::get_random
0000s0sSympa::Tools::Password::::password_validationSympa::Tools::Password::password_validation
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# -*- indent-tabs-mode: nil; -*-
2# vim:ft=perl:et:sw=4
3# $Id$
4
5# Sympa - SYsteme de Multi-Postage Automatique
6#
7# Copyright (c) 1997, 1998, 1999 Institut Pasteur & Christophe Wolfhugel
8# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
9# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
10# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
11# Copyright 2019 The Sympa Community. See the AUTHORS.md file at
12# the top-level directory of this distribution and at
13# <https://github.com/sympa-community/sympa.git>.
14#
15# This program is free software; you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation; either version 2 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28package Sympa::Tools::Password;
29
30use strict;
31use warnings;
32use Digest::MD5;
33BEGIN { eval 'use Data::Password'; }
# spent 0s executing statements in string eval
34
35use Conf;
36use Sympa::Language;
37
38# Deprecated. No longer used.
39#sub tmp_passwd;
40
41# No longer used, Use _decrypt_rc4_password() in upgrade_sympa_password.pl.
42#sub ciphersaber_installed;
43
44# No longer used.
45#sub crypt_password;
46
47# Moved: Use _decrypt_rc4_password() in upgrade_sympa_password.pl.
48#sub decrypt_password;
49
50# Old name: Sympa::Session::get_random().
51sub get_random {
52 # Concatenates two integers for a better entropy.
53 return sprintf '%07d%07d', int(rand(10**7)), int(rand(10**7));
54}
55
56my @validation_messages = (
57 {gettext_id => 'Not between %d and %d characters'},
58 {gettext_id => 'Not %d characters or greater'},
59 {gettext_id => 'Not less than or equal to %d characters'},
60 {gettext_id => 'contains bad characters'},
61 {gettext_id => 'contains less than %d character groups'},
62 {gettext_id => 'contains over %d leading characters in sequence'},
63 {gettext_id => "contains the dictionary word '%s'"},
64);
65
66# Old name: tools::password_validation().
67sub password_validation {
68 my ($password) = @_;
69
70 my $pv = $Conf::Conf{'password_validation'};
71 return undef
72 unless $pv
73 and defined $password
74 and $Data::Password::VERSION;
75
76 local (
77 $Data::Password::DICTIONARY, $Data::Password::FOLLOWING,
78 $Data::Password::GROUPS, $Data::Password::MINLEN,
79 $Data::Password::MAXLEN
80 );
81 local @Data::Password::DICTIONARIES = @Data::Password::DICTIONARIES;
82
83 my @techniques = split(/\s*,\s*/, $pv);
84 foreach my $technique (@techniques) {
85 my ($key, $value) = $technique =~ /([^=]+)=(.*)/;
86 $key = uc $key;
87
88 if ($key eq 'DICTIONARY') {
89 $Data::Password::DICTIONARY = $value;
90 } elsif ($key eq 'FOLLOWING') {
91 $Data::Password::FOLLOWING = $value;
92 } elsif ($key eq 'GROUPS') {
93 $Data::Password::GROUPS = $value;
94 } elsif ($key eq 'MINLEN') {
95 $Data::Password::MINLEN = $value;
96 } elsif ($key eq 'MAXLEN') {
97 $Data::Password::MAXLEN = $value;
98 } elsif ($key eq 'DICTIONARIES') {
99 # TODO: How do we handle a list of dictionaries?
100 push @Data::Password::DICTIONARIES, $value;
101 }
102 }
103 my $output = Data::Password::IsBadPassword($password);
104 return undef unless $output;
105
106 # Translate result if possible.
107 my $language = Sympa::Language->instance;
108 foreach my $item (@validation_messages) {
109 my $format = $item->{'gettext_id'};
110 my $regexp = quotemeta $format;
111 $regexp =~ s/\\\%[sd]/(.+)/g;
112
113 my ($match, @args) = ($output =~ /($regexp)/i);
114 next unless $match;
115 return $language->gettext_sprintf($format, @args);
116 }
117 return $output;
118}
119
1201;