New module 'Password Policy'
This commit is contained in:
parent
78ad431fbe
commit
0eade8428b
26 changed files with 3936 additions and 0 deletions
339
sites/all/modules/password_policy/LICENSE.txt
Normal file
339
sites/all/modules/password_policy/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
License is intended to guarantee your freedom to share and change free
|
||||||
|
software--to make sure the software is free for all its users. This
|
||||||
|
General Public License applies to most of the Free Software
|
||||||
|
Foundation's software and to any other program whose authors commit to
|
||||||
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
|
the GNU Lesser General Public License instead.) You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
this service if you wish), that you receive source code or can get it
|
||||||
|
if you want it, that you can change the software or use pieces of it
|
||||||
|
in new free programs; and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
anyone to deny you these rights or to ask you to surrender the rights.
|
||||||
|
These restrictions translate to certain responsibilities for you if you
|
||||||
|
distribute copies of the software, or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must give the recipients all the rights that
|
||||||
|
you have. You must make sure that they, too, receive or can get the
|
||||||
|
source code. And you must show them these terms so they know their
|
||||||
|
rights.
|
||||||
|
|
||||||
|
We protect your rights with two steps: (1) copyright the software, and
|
||||||
|
(2) offer you this license which gives you legal permission to copy,
|
||||||
|
distribute and/or modify the software.
|
||||||
|
|
||||||
|
Also, for each author's protection and ours, we want to make certain
|
||||||
|
that everyone understands that there is no warranty for this free
|
||||||
|
software. If the software is modified by someone else and passed on, we
|
||||||
|
want its recipients to know that what they have is not the original, so
|
||||||
|
that any problems introduced by others will not reflect on the original
|
||||||
|
authors' reputations.
|
||||||
|
|
||||||
|
Finally, any free program is threatened constantly by software
|
||||||
|
patents. We wish to avoid the danger that redistributors of a free
|
||||||
|
program will individually obtain patent licenses, in effect making the
|
||||||
|
program proprietary. To prevent this, we have made it clear that any
|
||||||
|
patent must be licensed for everyone's free use or not licensed at all.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License applies to any program or other work which contains
|
||||||
|
a notice placed by the copyright holder saying it may be distributed
|
||||||
|
under the terms of this General Public License. The "Program", below,
|
||||||
|
refers to any such program or work, and a "work based on the Program"
|
||||||
|
means either the Program or any derivative work under copyright law:
|
||||||
|
that is to say, a work containing the Program or a portion of it,
|
||||||
|
either verbatim or with modifications and/or translated into another
|
||||||
|
language. (Hereinafter, translation is included without limitation in
|
||||||
|
the term "modification".) Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running the Program is not restricted, and the output from the Program
|
||||||
|
is covered only if its contents constitute a work based on the
|
||||||
|
Program (independent of having been made by running the Program).
|
||||||
|
Whether that is true depends on what the Program does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Program's
|
||||||
|
source code as you receive it, in any medium, provided that you
|
||||||
|
conspicuously and appropriately publish on each copy an appropriate
|
||||||
|
copyright notice and disclaimer of warranty; keep intact all the
|
||||||
|
notices that refer to this License and to the absence of any warranty;
|
||||||
|
and give any other recipients of the Program a copy of this License
|
||||||
|
along with the Program.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy, and
|
||||||
|
you may at your option offer warranty protection in exchange for a fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Program or any portion
|
||||||
|
of it, thus forming a work based on the Program, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) You must cause the modified files to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
b) You must cause any work that you distribute or publish, that in
|
||||||
|
whole or in part contains or is derived from the Program or any
|
||||||
|
part thereof, to be licensed as a whole at no charge to all third
|
||||||
|
parties under the terms of this License.
|
||||||
|
|
||||||
|
c) If the modified program normally reads commands interactively
|
||||||
|
when run, you must cause it, when started running for such
|
||||||
|
interactive use in the most ordinary way, to print or display an
|
||||||
|
announcement including an appropriate copyright notice and a
|
||||||
|
notice that there is no warranty (or else, saying that you provide
|
||||||
|
a warranty) and that users may redistribute the program under
|
||||||
|
these conditions, and telling the user how to view a copy of this
|
||||||
|
License. (Exception: if the Program itself is interactive but
|
||||||
|
does not normally print such an announcement, your work based on
|
||||||
|
the Program is not required to print an announcement.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Program,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Program, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Program.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Program
|
||||||
|
with the Program (or with a work based on the Program) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may copy and distribute the Program (or a work based on it,
|
||||||
|
under Section 2) in object code or executable form under the terms of
|
||||||
|
Sections 1 and 2 above provided that you also do one of the following:
|
||||||
|
|
||||||
|
a) Accompany it with the complete corresponding machine-readable
|
||||||
|
source code, which must be distributed under the terms of Sections
|
||||||
|
1 and 2 above on a medium customarily used for software interchange; or,
|
||||||
|
|
||||||
|
b) Accompany it with a written offer, valid for at least three
|
||||||
|
years, to give any third party, for a charge no more than your
|
||||||
|
cost of physically performing source distribution, a complete
|
||||||
|
machine-readable copy of the corresponding source code, to be
|
||||||
|
distributed under the terms of Sections 1 and 2 above on a medium
|
||||||
|
customarily used for software interchange; or,
|
||||||
|
|
||||||
|
c) Accompany it with the information you received as to the offer
|
||||||
|
to distribute corresponding source code. (This alternative is
|
||||||
|
allowed only for noncommercial distribution and only if you
|
||||||
|
received the program in object code or executable form with such
|
||||||
|
an offer, in accord with Subsection b above.)
|
||||||
|
|
||||||
|
The source code for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For an executable work, complete source
|
||||||
|
code means all the source code for all modules it contains, plus any
|
||||||
|
associated interface definition files, plus the scripts used to
|
||||||
|
control compilation and installation of the executable. However, as a
|
||||||
|
special exception, the source code distributed need not include
|
||||||
|
anything that is normally distributed (in either source or binary
|
||||||
|
form) with the major components (compiler, kernel, and so on) of the
|
||||||
|
operating system on which the executable runs, unless that component
|
||||||
|
itself accompanies the executable.
|
||||||
|
|
||||||
|
If distribution of executable or object code is made by offering
|
||||||
|
access to copy from a designated place, then offering equivalent
|
||||||
|
access to copy the source code from the same place counts as
|
||||||
|
distribution of the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
4. You may not copy, modify, sublicense, or distribute the Program
|
||||||
|
except as expressly provided under this License. Any attempt
|
||||||
|
otherwise to copy, modify, sublicense or distribute the Program is
|
||||||
|
void, and will automatically terminate your rights under this License.
|
||||||
|
However, parties who have received copies, or rights, from you under
|
||||||
|
this License will not have their licenses terminated so long as such
|
||||||
|
parties remain in full compliance.
|
||||||
|
|
||||||
|
5. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Program or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Program (or any work based on the
|
||||||
|
Program), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Program or works based on it.
|
||||||
|
|
||||||
|
6. Each time you redistribute the Program (or any work based on the
|
||||||
|
Program), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute or modify the Program subject to
|
||||||
|
these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties to
|
||||||
|
this License.
|
||||||
|
|
||||||
|
7. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Program at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Program by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Program.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under
|
||||||
|
any particular circumstance, the balance of the section is intended to
|
||||||
|
apply and the section as a whole is intended to apply in other
|
||||||
|
circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system, which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
8. If the distribution and/or use of the Program is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Program under this License
|
||||||
|
may add an explicit geographical distribution limitation excluding
|
||||||
|
those countries, so that distribution is permitted only in or among
|
||||||
|
countries not thus excluded. In such case, this License incorporates
|
||||||
|
the limitation as if written in the body of this License.
|
||||||
|
|
||||||
|
9. The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Program
|
||||||
|
specifies a version number of this License which applies to it and "any
|
||||||
|
later version", you have the option of following the terms and conditions
|
||||||
|
either of that version or of any later version published by the Free
|
||||||
|
Software Foundation. If the Program does not specify a version number of
|
||||||
|
this License, you may choose any version ever published by the Free Software
|
||||||
|
Foundation.
|
||||||
|
|
||||||
|
10. If you wish to incorporate parts of the Program into other free
|
||||||
|
programs whose distribution conditions are different, write to the author
|
||||||
|
to ask for permission. For software which is copyrighted by the Free
|
||||||
|
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||||
|
make exceptions for this. Our decision will be guided by the two goals
|
||||||
|
of preserving the free status of all derivatives of our free software and
|
||||||
|
of promoting the sharing and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||||
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||||
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||||
|
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||||
|
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||||
|
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||||
|
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||||
|
REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||||
|
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||||
|
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||||
|
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||||
|
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||||
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program is interactive, make it output a short notice like this
|
||||||
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
|
Gnomovision version 69, Copyright (C) year name of author
|
||||||
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, the commands you use may
|
||||||
|
be called something other than `show w' and `show c'; they could even be
|
||||||
|
mouse-clicks or menu items--whatever suits your program.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||||
|
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 1 April 1989
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
This General Public License does not permit incorporating your program into
|
||||||
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
|
consider it more useful to permit linking proprietary applications with the
|
||||||
|
library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License.
|
78
sites/all/modules/password_policy/README.txt
Normal file
78
sites/all/modules/password_policy/README.txt
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
|
||||||
|
Password policy
|
||||||
|
==========================================
|
||||||
|
This module provides a way to specify a certain level of password
|
||||||
|
complexity (aka. "password hardening") for user passwords on a
|
||||||
|
system by defining a password policy.
|
||||||
|
|
||||||
|
A password policy can be defined with a set of constraints which
|
||||||
|
must be met before a user password change will be accepted. Each
|
||||||
|
constraint has a parameter allowing for the minimum number of valid
|
||||||
|
conditions which must be met before the constraint is satisfied.
|
||||||
|
|
||||||
|
Example: an uppercase constraint (with a parameter of 2) and a
|
||||||
|
digit constraint (with a parameter of 4) means that a user password
|
||||||
|
must have at least 2 uppercase letters and at least 4 digits for it
|
||||||
|
to be accepted.
|
||||||
|
|
||||||
|
Current constraints include:
|
||||||
|
|
||||||
|
* Digit constraint
|
||||||
|
* Letter constraint
|
||||||
|
* Letter/Digit constraint (Alphanumeric)
|
||||||
|
* Length constraint
|
||||||
|
* Uppercase constraint
|
||||||
|
* Lowercase constraint
|
||||||
|
* Punctuation constraint
|
||||||
|
* Character types constraint (allows the administrator to set the minimum
|
||||||
|
number of character types required, but without actually dictating which
|
||||||
|
ones must be used. Example - Windows requires any 3 (user's choice) of
|
||||||
|
uppercase, lowercase, numbers, or punctuation.
|
||||||
|
* History constraint (checks hashed password against a
|
||||||
|
collection of users previous hashed passwords looking for
|
||||||
|
recent duplicates)
|
||||||
|
* Username constraint
|
||||||
|
|
||||||
|
The module also implements configurable password expiration features:
|
||||||
|
|
||||||
|
* When a password is not changed for a certain amount of time the user will
|
||||||
|
be forced to change their password on next login.
|
||||||
|
* Optionally, the user will also be blocked upon password expiration.
|
||||||
|
* Expiration of passwords can begin after expiration time from enabling
|
||||||
|
the policy or immediately all users with passwords older than expiration
|
||||||
|
time will be blocked (retroactive behavior).
|
||||||
|
* Expiration notifications (warnings) are mailed to the users several times
|
||||||
|
(configurable) before the password expires.
|
||||||
|
* Warning e-mail message's subject and body are configurable.
|
||||||
|
|
||||||
|
Limitations
|
||||||
|
==========================================
|
||||||
|
Password policies only apply to passwords set via user forms in the web
|
||||||
|
interface. Passwords changed by other means (Drush, web services, etc.) will
|
||||||
|
not be subject to password policy constraints. Please see the following issue
|
||||||
|
if you would like to contribute to removing this limitation:
|
||||||
|
|
||||||
|
https://www.drupal.org/node/2451159
|
||||||
|
|
||||||
|
Security note
|
||||||
|
==========================================
|
||||||
|
Enforcing tough policy is only good from a technical standpoint. You are
|
||||||
|
likely to end up with a situation where the users write down their super
|
||||||
|
secure and super impossible to remember passwords. Help texts on how can
|
||||||
|
you memorize such things (like shifting a word one row up the keyboard
|
||||||
|
and so on). You should have separate company policy that deters users from
|
||||||
|
writing passwords on a Post-it on the backside of their keyboard.
|
||||||
|
|
||||||
|
Consider a company policy to use strong password generator tools like
|
||||||
|
http://supergenpass.com/ or 1Password on MacOS.
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
==========================================
|
||||||
|
Drupal 6.x
|
||||||
|
MySQL 5.0.3 or something else which supports varchar > 255
|
||||||
|
|
||||||
|
Credits
|
||||||
|
==========================================
|
||||||
|
Drupal 4.7 version was written by David Ayre <drupal at ayre dot ca>
|
||||||
|
Refactored and maintained by Miglius Alaburda <miglius at gmail dot com>
|
||||||
|
Sponsored by Bryght, SPAWAR, McDean
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Password policy constraint callbacks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Constraint API */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_alphanumeric_description() {
|
||||||
|
return array('name' => t('Alphanumeric'), 'description' => t('Password must contain the specified minimum number of alphanumeric (letters or numbers) characters.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_alphanumeric_error($constraint) {
|
||||||
|
return format_plural($constraint, 'Password must contain at least one alphanumeric (letter or number) character.', 'Password must contain at least @count alphanumeric (letter or number) characters.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password validation.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_alphanumeric_validate($password, $constraint, $uid) {
|
||||||
|
$length = drupal_strlen($password);
|
||||||
|
$num = 0;
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
if (ctype_alnum($password[$i]))
|
||||||
|
$num++;
|
||||||
|
}
|
||||||
|
return $num >= $constraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Javascript portion.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_alphanumeric_js($constraint, $uid) {
|
||||||
|
$s = '';
|
||||||
|
$s .= " var i=0;\n";
|
||||||
|
$s .= " var num=0;\n";
|
||||||
|
$s .= " var chr=\"\";\n";
|
||||||
|
$s .= " while(i<value.length) {\n";
|
||||||
|
$s .= " chr=value.charAt(i);\n";
|
||||||
|
$s .= " if(chr.toUpperCase() != chr.toLowerCase() || \"1234567890\".indexOf(chr) != -1) {\n";
|
||||||
|
$s .= " num++;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " i++;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " if (num<$constraint) {\n";
|
||||||
|
$s .= " strength=\"low\";\n";
|
||||||
|
$s .= " msg.push(translate.constraint_alphanumeric);\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
return $s;
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Password policy constraint callbacks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Constraint API */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_complexity_description() {
|
||||||
|
return array('name' => t('Complexity'), 'description' => t('Password must contain the specified minimum number of character types (lowercase, uppercase, digit or punctuation).'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_complexity_error($constraint) {
|
||||||
|
return format_plural($constraint, 'Password must contain at least one character of the following types: lowercase, uppercase, digit or punctuation.', 'Password must contain at least @count characters of different types (lowercase, uppercase, digit or punctuation).');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password validation.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_complexity_validate($password, $constraint, $uid) {
|
||||||
|
$length = drupal_strlen($password);
|
||||||
|
$num = 0;
|
||||||
|
$upper = 0;
|
||||||
|
$lower = 0;
|
||||||
|
$digit = 0;
|
||||||
|
$punct = 0;
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
if (ctype_upper($password[$i])) {
|
||||||
|
$upper = 1;
|
||||||
|
}
|
||||||
|
elseif (ctype_lower($password[$i])) {
|
||||||
|
$lower = 1;
|
||||||
|
}
|
||||||
|
elseif (ctype_digit($password[$i])) {
|
||||||
|
$digit = 1;
|
||||||
|
}
|
||||||
|
elseif (ctype_punct($password[$i])) {
|
||||||
|
$punct = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$num = $upper + $lower + $digit + $punct;
|
||||||
|
return $num >= $constraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Javascript portion.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_complexity_js($constraint, $uid) {
|
||||||
|
$s = '';
|
||||||
|
$s .= " var i=0;\n";
|
||||||
|
$s .= " var num=0;\n";
|
||||||
|
$s .= " var upper=0;\n";
|
||||||
|
$s .= " var lower=0;\n";
|
||||||
|
$s .= " var digit=0;\n";
|
||||||
|
$s .= " var punct=0;\n";
|
||||||
|
$s .= " var chr=\"\";\n";
|
||||||
|
$s .= " while(i<value.length) {\n";
|
||||||
|
$s .= " chr=value.charAt(i);\n";
|
||||||
|
$s .= " if(chr.toUpperCase() != chr.toLowerCase()) {\n";
|
||||||
|
$s .= " if(chr == chr.toUpperCase()) {\n";
|
||||||
|
$s .= " upper=1;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " else {\n";
|
||||||
|
$s .= " lower=1;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " else if(\"1234567890\".indexOf(chr) != -1) {\n";
|
||||||
|
$s .= " digit=1;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " else if(chr.toUpperCase() == chr.toLowerCase() && \"1234567890\".indexOf(chr) == -1 && chr != ' ') {\n";
|
||||||
|
$s .= " punct=1;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " i++;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " num=upper+lower+digit+punct\n";
|
||||||
|
$s .= " if (num<$constraint) {\n";
|
||||||
|
$s .= " strength=\"low\";\n";
|
||||||
|
$s .= " msg.push(translate.constraint_complexity);\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
return $s;
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Password policy constraint callback to set a minimum delay between password
|
||||||
|
* changes.
|
||||||
|
*
|
||||||
|
* @link http://drupal.org/node/316765
|
||||||
|
* @author David Kent Norman (http://deekayen.net/)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Constraint API */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_delay_description() {
|
||||||
|
return array('name' => t('Delay'), 'description' => t('Minimum number of hours between password changes.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_delay_error($constraint) {
|
||||||
|
return format_plural($constraint, 'Password may only be changed in an hour from the last change.', 'Password may only be changed in @count hours from the last change.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password validation.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_delay_validate($password, $constraint, $uid) {
|
||||||
|
$account = user_load($uid);
|
||||||
|
// bypass delay constraint, if account is marked "Force password change on
|
||||||
|
// next login."
|
||||||
|
if ($account->force_password_change) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$last_change = db_result(db_query_range("SELECT MAX(created) FROM {password_policy_history} WHERE uid = %d", $uid, 0, 1));
|
||||||
|
if (!empty($last_change)) {
|
||||||
|
// Constraint is set in hours, so it gets converted to seconds with *60*60.
|
||||||
|
return time() - ($constraint*60*60) > $last_change;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
function password_policy_constraint_delay_js() {
|
||||||
|
return '';
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Password policy constraint callbacks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Constraint API */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_digit_description() {
|
||||||
|
return array('name' => t('Digit'), 'description' => t('Password must contain the specified minimum number of digits.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_digit_error($constraint) {
|
||||||
|
return format_plural($constraint, 'Password must contain at least one digit.', 'Password must contain at least @count digits.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password validation.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_digit_validate($password, $constraint, $uid) {
|
||||||
|
$length = drupal_strlen($password);
|
||||||
|
$num = 0;
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
if (ctype_digit($password[$i]))
|
||||||
|
$num++;
|
||||||
|
}
|
||||||
|
return $num >= $constraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Javascript portion.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_digit_js($constraint, $uid) {
|
||||||
|
$s = '';
|
||||||
|
$s .= " var i=0;\n";
|
||||||
|
$s .= " var num=0;\n";
|
||||||
|
$s .= " var chr=\"\";\n";
|
||||||
|
$s .= " while(i<value.length) {\n";
|
||||||
|
$s .= " chr=value.charAt(i);\n";
|
||||||
|
$s .= " if(\"1234567890\".indexOf(chr) != -1) {\n";
|
||||||
|
$s .= " num++;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " i++;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " if (num<$constraint) {\n";
|
||||||
|
$s .= " strength=\"low\";\n";
|
||||||
|
$s .= " msg.push(translate.constraint_digit);\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
return $s;
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Restrict placement of digits in passwords.
|
||||||
|
*
|
||||||
|
* @link http://drupal.org/node/316768
|
||||||
|
* @author David Kent Norman (http://deekayen.net/)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Constraint API */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_digit_placement_description() {
|
||||||
|
return array('name' => t('Digit Placement'), 'description' => t('Minimum number of digits in the password to allow a digit in the first or last position in the password (e.g. 2abcdefg and abcdefg4 are unacceptable passwords, while 2qpcxrm3 and 99qpcxrm are allowed passwords when 2 is set here).'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_digit_placement_error($constraint) {
|
||||||
|
return t('Password must have a minimum of %numChars %digits in order to place any digits at the start or end of the password.',
|
||||||
|
array('%numChars' => $constraint,
|
||||||
|
'%digits' => format_plural($constraint, t('digit'), t('digits'))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password validation.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_digit_placement_validate($password, $constraint, $uid) {
|
||||||
|
$number_of_digits = 0;
|
||||||
|
for ($i=0; $i<10; $i++) {
|
||||||
|
// help string count by sending it a string instead of an int
|
||||||
|
$number_of_digits += substr_count($password, "$i");
|
||||||
|
}
|
||||||
|
if ($number_of_digits < (int)$constraint) {
|
||||||
|
return preg_match("/^(\d+)|(\d+)$/", $password) != 1;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Javascript portion.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_digit_placement_js($constraint, $uid) {
|
||||||
|
return <<<JSS
|
||||||
|
function substr_count(haystack, needle) {
|
||||||
|
var pos = 0, cnt = 0;
|
||||||
|
|
||||||
|
haystack += '';
|
||||||
|
needle += '';
|
||||||
|
var offset = 0;
|
||||||
|
var length = 0;
|
||||||
|
offset--;
|
||||||
|
|
||||||
|
while ((offset = haystack.indexOf(needle, offset+1)) != -1) {
|
||||||
|
if (length > 0 && (offset+needle.length) > length) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
var i=0;
|
||||||
|
var num=0;
|
||||||
|
for (i=0;i<10;i++) {
|
||||||
|
num += substr_count(value, i);
|
||||||
|
}
|
||||||
|
if (num<$constraint && value.match(/^(\d+)|(\d+)$/) != null) {
|
||||||
|
strength="low";
|
||||||
|
msg.push(translate.constraint_digit_placement);
|
||||||
|
}
|
||||||
|
JSS;
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Password policy constraint callbacks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Constraint API */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_history_description() {
|
||||||
|
return array('name' => t('History'), 'description' => t('Password must not match any of the user\'s previous X passwords.') . ' <br/><b>' . t('Note: ') . '</b>' . t('This constraint can only compare a new password with the previous passwords recorded since the password policy module was enabled. For example, if the number of previous passwords is set to 3, the module may have only recorded 2 password changes since the module was enabled. If the recorded password history is not large enough to support the constraint history size, the history size for the constraint will be reduced (temporarily during the constraint check) to match the available recorded history. Also note that a history size of 1 means that the user is unable to change their password to their current password. This can be useful in certain situations, but a setting of 2+ will likely be more useful.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_history_error($constraint) {
|
||||||
|
return format_plural($constraint, 'Password must not match last password.', 'Password must not match last @count passwords.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password validation.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_history_validate($password, $constraint, $uid) {
|
||||||
|
$old_hashes = _password_policy_constraint_history_old_passwords($constraint, $uid);
|
||||||
|
if (module_exists('phpass')) {
|
||||||
|
module_load_include('inc', 'phpass', 'password');
|
||||||
|
$account = new stdClass();
|
||||||
|
foreach ($old_hashes as $old_hash) {
|
||||||
|
$account->pass = $old_hash;
|
||||||
|
if (user_check_password($password, $account)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$hash = md5($password);
|
||||||
|
return !in_array($hash, $old_hashes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Auxiliary */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets old password hashes.
|
||||||
|
*/
|
||||||
|
function _password_policy_constraint_history_old_passwords($constraint, $uid) {
|
||||||
|
$pass = array();
|
||||||
|
if (!empty($uid)) {
|
||||||
|
// note that we specify a limit of the window size, but may not get that if
|
||||||
|
// the history isn't there.
|
||||||
|
$result = db_query("SELECT pass FROM {password_policy_history} WHERE uid =
|
||||||
|
%d ORDER BY created DESC LIMIT %d", $uid, $constraint);
|
||||||
|
while ($row = db_fetch_array($result)) {
|
||||||
|
$pass[] = $row['pass'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $pass;
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Password policy constraint callbacks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Constraint API */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_length_description() {
|
||||||
|
return array('name' => t('Length'), 'description' => t('Password must be longer than the specified minimum length.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_length_error($constraint) {
|
||||||
|
return format_plural($constraint, 'Password must be at least one character in length.', 'Password must be at least @count characters in length.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password validation.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_length_validate($password, $constraint, $uid) {
|
||||||
|
$length = drupal_strlen($password);
|
||||||
|
return $length >= $constraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Javascript portion.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_length_js($constraint, $uid) {
|
||||||
|
$s = '';
|
||||||
|
$s .= " if (!value.length || value.length<$constraint) {\n";
|
||||||
|
$s .= " strength=\"low\";\n";
|
||||||
|
$s .= " msg.push(translate.constraint_length);\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
return $s;
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Password policy constraint callbacks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Constraint API */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_letter_description() {
|
||||||
|
return array('name' => t('Letter'), 'description' => t('Password must contain the specified minimum number of letters.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_letter_error($constraint) {
|
||||||
|
return format_plural($constraint, 'Password must contain at least one letter.', 'Password must contain at least @count letters.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password validation.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_letter_validate($password, $constraint, $uid) {
|
||||||
|
$length = drupal_strlen($password);
|
||||||
|
$num = 0;
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
if (ctype_alpha($password[$i]))
|
||||||
|
$num++;
|
||||||
|
}
|
||||||
|
return $num >= $constraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Javascript portion.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_letter_js($constraint, $uid) {
|
||||||
|
$s = '';
|
||||||
|
$s .= " var i=0;\n";
|
||||||
|
$s .= " var num=0;\n";
|
||||||
|
$s .= " var chr=\"\";\n";
|
||||||
|
$s .= " while(i<value.length) {\n";
|
||||||
|
$s .= " chr=value.charAt(i);\n";
|
||||||
|
$s .= " if(chr.toUpperCase() != chr.toLowerCase()) {\n";
|
||||||
|
$s .= " num++;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " i++;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " if (num<$constraint) {\n";
|
||||||
|
$s .= " strength=\"low\";\n";
|
||||||
|
$s .= " msg.push(translate.constraint_letter);\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
return $s;
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Password policy constraint callbacks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Constraint API */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_lowercase_description() {
|
||||||
|
return array('name' => t('Lowercase'), 'description' => t('Password must contain the specified minimum number of lowercase letters.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_lowercase_error($constraint) {
|
||||||
|
return format_plural($constraint, 'Password must contain at least one lowercase character.', 'Password must contain at least @count lowercase characters.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password validation.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_lowercase_validate($password, $constraint, $uid) {
|
||||||
|
$length = drupal_strlen($password);
|
||||||
|
$num = 0;
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
if (ctype_lower($password[$i]))
|
||||||
|
$num++;
|
||||||
|
}
|
||||||
|
return $num >= $constraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Javascript portion.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_lowercase_js($constraint, $uid) {
|
||||||
|
$s = '';
|
||||||
|
$s .= " var i=0;\n";
|
||||||
|
$s .= " var num=0;\n";
|
||||||
|
$s .= " var chr=\"\";\n";
|
||||||
|
$s .= " while(i<value.length) {\n";
|
||||||
|
$s .= " chr=value.charAt(i);\n";
|
||||||
|
$s .= " if(chr.toUpperCase() != chr.toLowerCase()) {\n";
|
||||||
|
$s .= " if(chr == chr.toLowerCase()) {\n";
|
||||||
|
$s .= " num++;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " i++;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " if (num<$constraint) {\n";
|
||||||
|
$s .= " strength=\"low\";\n";
|
||||||
|
$s .= " msg.push(translate.constraint_lowercase);\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
return $s;
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Password policy constraint callbacks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Constraint API */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_punctuation_description() {
|
||||||
|
return array('name' => t('Punctuation'), 'description' => t('Password must contain the specified minimum number of punctuation (not whitespace or an alphanumeric) characters.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_punctuation_error($constraint) {
|
||||||
|
return format_plural($constraint, 'Password must contain at least one punctuation (not whitespace or an alphanumeric) character.', 'Password must contain at least @count punctuation (not whitespace or an alphanumeric) characters.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password validation.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_punctuation_validate($password, $constraint, $uid) {
|
||||||
|
$length = drupal_strlen($password);
|
||||||
|
$num = 0;
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
if (ctype_punct($password[$i]))
|
||||||
|
$num++;
|
||||||
|
}
|
||||||
|
return $num >= $constraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Javascript portion.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_punctuation_js($constraint, $uid) {
|
||||||
|
$s = '';
|
||||||
|
$s .= " var i=0;\n";
|
||||||
|
$s .= " var num=0;\n";
|
||||||
|
$s .= " var chr=\"\";\n";
|
||||||
|
$s .= " while(i<value.length) {\n";
|
||||||
|
$s .= " chr=value.charAt(i);\n";
|
||||||
|
$s .= " if(chr.toUpperCase() == chr.toLowerCase() && \"1234567890\".indexOf(chr) == -1 && chr != ' ') {\n";
|
||||||
|
$s .= " num++;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " i++;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " if (num<$constraint) {\n";
|
||||||
|
$s .= " strength=\"low\";\n";
|
||||||
|
$s .= " msg.push(translate.constraint_punctuation);\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
return $s;
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Password policy constraint callbacks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Constraint API */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_uppercase_description() {
|
||||||
|
return array('name' => t('Uppercase'), 'description' => t('Password must contain the specified minimum number of uppercase letters.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_uppercase_error($constraint) {
|
||||||
|
return format_plural($constraint, 'Password must contain at least one uppercase character.', 'Password must contain at least @count uppercase characters.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password validation.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_uppercase_validate($password, $constraint, $uid) {
|
||||||
|
$length = drupal_strlen($password);
|
||||||
|
$num = 0;
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
if (ctype_upper($password[$i]))
|
||||||
|
$num++;
|
||||||
|
}
|
||||||
|
return $num >= $constraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Javascript portion.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_uppercase_js($constraint, $uid) {
|
||||||
|
$s = '';
|
||||||
|
$s .= " var i=0;\n";
|
||||||
|
$s .= " var num=0;\n";
|
||||||
|
$s .= " var chr=\"\";\n";
|
||||||
|
$s .= " while(i<value.length) {\n";
|
||||||
|
$s .= " chr=value.charAt(i);\n";
|
||||||
|
$s .= " if(chr.toUpperCase() != chr.toLowerCase()) {\n";
|
||||||
|
$s .= " if(chr == chr.toUpperCase()) {\n";
|
||||||
|
$s .= " num++;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " i++;\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
$s .= " if (num<$constraint) {\n";
|
||||||
|
$s .= " strength=\"low\";\n";
|
||||||
|
$s .= " msg.push(translate.constraint_uppercase);\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
return $s;
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Password policy constraint callbacks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Constraint API */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_username_description() {
|
||||||
|
return array('name' => t('Username'), 'description' => t('Password must not contain the username (case insensitive). Put any positive number to enforce this policy.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message of the constraint.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_username_error($constraint) {
|
||||||
|
return t('Password must not contain the username.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password validation.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_username_validate($password, $constraint, $uid) {
|
||||||
|
$account = user_load(array('uid' => $uid));
|
||||||
|
if ($account->name == '') {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
$username_lowercase = drupal_strtolower($account->name);
|
||||||
|
$password_lowercase = drupal_strtolower($password);
|
||||||
|
if ($constraint && (strpos($password_lowercase, $username_lowercase) !== FALSE)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Javascript portion.
|
||||||
|
*/
|
||||||
|
function password_policy_constraint_username_js($constraint, $uid) {
|
||||||
|
// Add username as JavaScript setting.
|
||||||
|
$account = user_load(array('uid' => $uid));
|
||||||
|
$username = $account->name;
|
||||||
|
if ($username == '') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$data = array(
|
||||||
|
'password_policy' => array(
|
||||||
|
'username' => $username,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
drupal_add_js($data, 'setting');
|
||||||
|
|
||||||
|
$s = '';
|
||||||
|
if ($constraint) {
|
||||||
|
$s .= " var username=Drupal.settings.password_policy.username;\n";
|
||||||
|
$s .= " var username_lowercase=username.toLowerCase();\n";
|
||||||
|
$s .= " var password_lowercase=value.toLowerCase();\n";
|
||||||
|
$s .= " if (password_lowercase.indexOf(username_lowercase) != -1) {\n";
|
||||||
|
$s .= " strength=\"low\";\n";
|
||||||
|
$s .= " msg.push(translate.constraint_username);\n";
|
||||||
|
$s .= " }\n";
|
||||||
|
}
|
||||||
|
return $s;
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Module admin page callbacks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Password policy password tab settings */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements the settings page.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* The form structure.
|
||||||
|
*/
|
||||||
|
function password_policy_password_tab_admin_settings() {
|
||||||
|
$form = array();
|
||||||
|
|
||||||
|
// Attachments settings.
|
||||||
|
$form['password_tab'] = array('#type' => 'fieldset', '#title' => t('Password tab settings'), '#collapsible' => FALSE, '#collapsed' => FALSE);
|
||||||
|
$form['password_tab']['password_policy_password_tab_redirect'] = array(
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#title' => t('Redirect path on password change'),
|
||||||
|
'#default_value' => variable_get('password_policy_password_tab_redirect', ''),
|
||||||
|
'#description' => t('Normally, after a user changes their password, they will be taken to their user page. Leave this setting blank if you wish to keep the default behavior. If you wish the user to go to a page of your choosing, then enter the path for it here. For instance, you may redirect them to a static page such as <cite>node/35</cite>, or to the <cite><front></cite> page. You may also use <em>%uid</em> as a variable, and the user\'s user ID will be substituted in the path. In the case where users are first creating their own passwords, it is suggested to use <cite>user/%uid/edit</cite> here, so the user may set their over account information immediately after validating their account.'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['submit'] = array(
|
||||||
|
'#type' => 'submit',
|
||||||
|
'#value' => t('Save configuration'),
|
||||||
|
);
|
||||||
|
$form['reset'] = array(
|
||||||
|
'#type' => 'submit',
|
||||||
|
'#value' => t('Reset to defaults'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit hook for the settings form.
|
||||||
|
*/
|
||||||
|
function password_policy_password_tab_admin_settings_submit($form, &$form_state) {
|
||||||
|
$op = $form_state['clicked_button']['#value'];
|
||||||
|
$values = $form_state['values'];
|
||||||
|
switch ($op) {
|
||||||
|
case t('Save configuration'):
|
||||||
|
variable_set('password_policy_password_tab_redirect', $values['password_policy_password_tab_redirect']);
|
||||||
|
drupal_set_message(t('The configuration options have been saved.'));
|
||||||
|
break;
|
||||||
|
case t('Reset to defaults'):
|
||||||
|
variable_del('password_policy_password_tab_redirect');
|
||||||
|
drupal_set_message(t('The configuration options have been reset to their default values.'));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
name = Password change tab
|
||||||
|
description = Implements a separate password change tab.
|
||||||
|
package = Security
|
||||||
|
dependencies[] = password_policy
|
||||||
|
core = 6.x
|
||||||
|
|
||||||
|
; Information added by Drupal.org packaging script on 2015-03-31
|
||||||
|
version = "6.x-1.11"
|
||||||
|
core = "6.x"
|
||||||
|
project = "password_policy"
|
||||||
|
datestamp = "1427843284"
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Password policy password tab module installation and upgrade code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Module installation/uninstallation */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_install().
|
||||||
|
*/
|
||||||
|
function password_policy_password_tab_install() {
|
||||||
|
if (variable_get('password_policy_change_url', NULL) == NULL) {
|
||||||
|
variable_set('password_policy_change_url', 'password');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_uninstall().
|
||||||
|
*/
|
||||||
|
function password_policy_password_tab_uninstall() {
|
||||||
|
variable_del('password_policy_password_tab_redirect');
|
||||||
|
|
||||||
|
if (variable_get('password_policy_change_url', NULL) == 'password') {
|
||||||
|
variable_del('password_policy_change_url');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set default value for password change URL.
|
||||||
|
*/
|
||||||
|
function password_policy_password_tab_6001() {
|
||||||
|
if (variable_get('password_policy_change_url', NULL) == NULL) {
|
||||||
|
variable_set('password_policy_change_url', 'password');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* The password policy password tab module adds a separate tab to change
|
||||||
|
* password.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Core API hooks */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_menu().
|
||||||
|
*/
|
||||||
|
function password_policy_password_tab_menu() {
|
||||||
|
return array(
|
||||||
|
'admin/settings/password_policy/password_tab' => array(
|
||||||
|
'title' => 'Password tab',
|
||||||
|
'page callback' => 'drupal_get_form',
|
||||||
|
'page arguments' => array('password_policy_password_tab_admin_settings'),
|
||||||
|
'access arguments' => array('administer site configuration'),
|
||||||
|
'file' => 'password_policy_password_tab.admin.inc',
|
||||||
|
),
|
||||||
|
'user/%user_category/edit/password' => array(
|
||||||
|
'title' => 'Password',
|
||||||
|
'page callback' => 'drupal_get_form',
|
||||||
|
'page arguments' => array('password_policy_password_tab', 1),
|
||||||
|
'access callback' => 'user_edit_access',
|
||||||
|
'access arguments' => array(1),
|
||||||
|
'type' => MENU_LOCAL_TASK,
|
||||||
|
'load arguments' => array('%map', '%index'),
|
||||||
|
'file' => 'password_policy_password_tab.pages.inc',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_user().
|
||||||
|
*/
|
||||||
|
function password_policy_password_tab_user($op, &$edit, &$account, $category = NULL) {
|
||||||
|
if ($op === 'categories') {
|
||||||
|
return array(array(
|
||||||
|
'name' => 'password',
|
||||||
|
'title' => t('Password'),
|
||||||
|
'weight' => 0,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_form_alter().
|
||||||
|
*/
|
||||||
|
function password_policy_password_tab_form_alter(&$form, $form_state, $form_id) {
|
||||||
|
switch ($form_id) {
|
||||||
|
case "user_profile_form":
|
||||||
|
// Hide core password field from user edit form.
|
||||||
|
unset($form['account']['pass']);
|
||||||
|
// Also hide password field added by Password Confirm module.
|
||||||
|
if (module_exists('password_change')) {
|
||||||
|
unset($form['pass_current']);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_exit().
|
||||||
|
*
|
||||||
|
* This function acts on a drupal_goto from user_pass_reset form. The user is
|
||||||
|
* redirected to the password change tab instead of the account edit form.
|
||||||
|
*/
|
||||||
|
function password_policy_password_tab_exit($destination = NULL) {
|
||||||
|
static $processed = FALSE;
|
||||||
|
|
||||||
|
// Check if this is a drupal_goto from the password reset page.
|
||||||
|
if (!$processed && isset($destination) && arg(0) == 'user' && arg(1) == 'reset') {
|
||||||
|
$url_parts = parse_url($destination);
|
||||||
|
// Check if the redirect has a path.
|
||||||
|
if (isset($url_parts['path'])) {
|
||||||
|
// Check if the redirect path is user/%user/edit.
|
||||||
|
$path = drupal_substr($url_parts['path'], 1);
|
||||||
|
$args = arg(NULL, $path);
|
||||||
|
if (count($args) == 3 && $args[0] == 'user' && $args[2] == 'edit') {
|
||||||
|
// Prevent loops.
|
||||||
|
$processed = TRUE;
|
||||||
|
// Change the drupal_goto to our change password tab.
|
||||||
|
$path .= '/password';
|
||||||
|
$query = isset($url_parts['query']) ? $url_parts['query'] : NULL;
|
||||||
|
$fragment = isset($url_parts['fragment']) ? $url_parts['fragment'] : NULL;
|
||||||
|
drupal_goto($path, $query, $fragment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* The password policy password tab page callbacks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password change form.
|
||||||
|
*/
|
||||||
|
function password_policy_password_tab(&$form_state, $account) {
|
||||||
|
$form['_category'] = array('#type' => 'value', '#value' => 'account');
|
||||||
|
$form['_account'] = array('#type' => 'value', '#value' => $account);
|
||||||
|
$form['#uid'] = $account->uid;
|
||||||
|
|
||||||
|
$form['account']['pass'] = array(
|
||||||
|
'#type' => 'password_confirm',
|
||||||
|
'#description' => t('To change the current user password, enter the new password in both fields.'),
|
||||||
|
'#size' => 25,
|
||||||
|
'#required' => TRUE,
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['submit'] = array('#type' => 'submit', '#value' => t('Change'));
|
||||||
|
|
||||||
|
$form['#validate'] = array('password_policy_password_tab_validate');
|
||||||
|
$form['#submit'] = array('password_policy_password_tab_submit');
|
||||||
|
|
||||||
|
// Show password field added by Password Change module.
|
||||||
|
if (module_exists('password_change')) {
|
||||||
|
password_change_form_user_profile_form_alter($form, $form_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
password_policy_form_alter($form, array(), 'user_profile_form');
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password change form validation.
|
||||||
|
*/
|
||||||
|
function password_policy_password_tab_validate($form, &$form_state) {
|
||||||
|
$values = $form_state['values'];
|
||||||
|
|
||||||
|
$pass = trim($values['pass']);
|
||||||
|
if (empty($pass)) {
|
||||||
|
form_set_error('pass', t('Your password cannot be empty.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password change form submit.
|
||||||
|
*/
|
||||||
|
function password_policy_password_tab_submit($form, &$form_state) {
|
||||||
|
$account = $form['_account']['#value'];
|
||||||
|
user_module_invoke('submit', $form_state['values'], $account, 'account');
|
||||||
|
user_save($account, array('pass' => $form_state['values']['pass']));
|
||||||
|
drupal_set_message(t('Password has been changed.'));
|
||||||
|
if (variable_get('password_policy_password_tab_redirect', '') && !preg_match('/[?&]destination=/', $form['#action'])) {
|
||||||
|
global $user;
|
||||||
|
$redirect = parse_url(urldecode(strtr(variable_get('password_policy_password_tab_redirect', ''), array('%uid' => $user->uid))));
|
||||||
|
$form_state['redirect'] = array($redirect['path'], isset($redirect['query']) ? $redirect['query'] : NULL, isset($redirect['fragment']) ? $redirect['fragment'] : NULL);
|
||||||
|
}
|
||||||
|
}
|
469
sites/all/modules/password_policy/password_policy.admin.inc
Normal file
469
sites/all/modules/password_policy/password_policy.admin.inc
Normal file
|
@ -0,0 +1,469 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Admin page callback file for the password_policy module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Password policy admin settings */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Settings form display.
|
||||||
|
*/
|
||||||
|
function password_policy_admin_settings() {
|
||||||
|
$form['expiration'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('Expiration settings'),
|
||||||
|
'#collapsible' => TRUE,
|
||||||
|
'#collapsed' => FALSE
|
||||||
|
);
|
||||||
|
$form['expiration']['password_policy_admin'] = array(
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Admin (UID=1) password expires.'),
|
||||||
|
'#default_value' => variable_get('password_policy_admin', 0),
|
||||||
|
'#description' => t('Admin account password will obey expiration policy.'),
|
||||||
|
);
|
||||||
|
$form['expiration']['password_policy_begin'] = array(
|
||||||
|
'#type' => 'radios',
|
||||||
|
'#title' => t('Beginning of password expirations'),
|
||||||
|
'#default_value' => variable_get('password_policy_begin', 0),
|
||||||
|
'#options' => array('0' => t('After expiration time from setting a default policy (all passwords are valid during the expiration time from setting the default policy, and after that older than expiration time passwords expire).'), '1' => t('Setting a default policy (passwords older than expiration time expire after setting the default policy, retroactive behaviour).')),
|
||||||
|
);
|
||||||
|
$form['expiration']['password_policy_block'] = array(
|
||||||
|
'#type' => 'radios',
|
||||||
|
'#title' => t('Blocking expired accounts'),
|
||||||
|
'#default_value' => variable_get('password_policy_block', 0),
|
||||||
|
'#options' => array('0' => t('Expired accounts are blocked. Only administrators can unblock them. Once unblocked, users can log in and will be forced to change their password. If they do not log in and change their password within one day, they will be blocked again.'), '1' => t('Expired accounts are not blocked. Users whose accounts have expired will be forced to change their passwords at next login.')),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Visibility
|
||||||
|
$form['visibility'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('Visibility settings'),
|
||||||
|
'#collapsible' => TRUE,
|
||||||
|
'#collapsed' => FALSE
|
||||||
|
);
|
||||||
|
$form['visibility']['password_policy_show_restrictions'] = array(
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Show all restrictions on password change page.'),
|
||||||
|
'#default_value' => variable_get('password_policy_show_restrictions', 0),
|
||||||
|
'#description' => t('List all password restrictions on the password change page. The list is displayed in addition to the default dynamic, JavaScript-generated list of only the restrictions the typed password does not meet. Enabling this setting allows a user who is not using JavaScript to see the password restrictions prior to submitting their password.'),
|
||||||
|
);
|
||||||
|
|
||||||
|
// E-mail notification settings.
|
||||||
|
$form['email'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('E-mail notification settings'),
|
||||||
|
'#collapsible' => TRUE,
|
||||||
|
'#collapsed' => TRUE
|
||||||
|
);
|
||||||
|
$form['email']['password_policy_warning_subject'] = array(
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#title' => t('Subject of warning e-mail'),
|
||||||
|
'#default_value' => _password_policy_mail_text('warning_subject'),
|
||||||
|
'#maxlength' => 180,
|
||||||
|
'#description' => t('Customize the subject of the warning e-mail message, which is sent to remind of password expiration.') . ' ' . t('Available variables are:') . ' !username, !site, !uri, !uri_brief, !mailto, !date, !login_uri, !edit_uri, !days_left.',
|
||||||
|
);
|
||||||
|
$form['email']['password_policy_warning_body'] = array(
|
||||||
|
'#type' => 'textarea',
|
||||||
|
'#title' => t('Body of warning e-mail'),
|
||||||
|
'#default_value' => _password_policy_mail_text('warning_body'),
|
||||||
|
'#rows' => 15,
|
||||||
|
'#description' => t('Customize the body of the warning e-mail message, which is sent to remind of password expiration.') . ' ' . t('Available variables are:') . ' !username, !site, !uri, !uri_brief, !mailto, !date, !login_uri, !edit_uri, !days_left.',
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['submit'] = array(
|
||||||
|
'#type' => 'submit',
|
||||||
|
'#value' => t('Save configuration'),
|
||||||
|
);
|
||||||
|
$form['reset'] = array(
|
||||||
|
'#type' => 'submit',
|
||||||
|
'#value' => t('Reset to defaults'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit hook for the settings form.
|
||||||
|
*/
|
||||||
|
function password_policy_admin_settings_submit($form, &$form_state) {
|
||||||
|
$op = $form_state['clicked_button']['#value'];
|
||||||
|
switch ($op) {
|
||||||
|
case t('Save configuration'):
|
||||||
|
variable_set('password_policy_admin', $form_state['values']['password_policy_admin']);
|
||||||
|
variable_set('password_policy_begin', $form_state['values']['password_policy_begin']);
|
||||||
|
variable_set('password_policy_block', $form_state['values']['password_policy_block']);
|
||||||
|
variable_set('password_policy_show_restrictions', $form_state['values']['password_policy_show_restrictions']);
|
||||||
|
variable_set('password_policy_warning_subject', $form_state['values']['password_policy_warning_subject']);
|
||||||
|
variable_set('password_policy_warning_body', $form_state['values']['password_policy_warning_body']);
|
||||||
|
drupal_set_message(t('The configuration options have been saved.'));
|
||||||
|
break;
|
||||||
|
case t('Reset to defaults'):
|
||||||
|
variable_del('password_policy_admin');
|
||||||
|
variable_del('password_policy_begin');
|
||||||
|
variable_del('password_policy_block');
|
||||||
|
variable_del('password_policy_show_restrictions');
|
||||||
|
variable_del('password_policy_warning_subject');
|
||||||
|
variable_del('password_policy_warning_body');
|
||||||
|
drupal_set_message(t('The configuration options have been reset to their default values.'));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists roles to which a policy applies.
|
||||||
|
*
|
||||||
|
* @param $pid
|
||||||
|
* Policy id.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* Array of role names.
|
||||||
|
*/
|
||||||
|
function _password_policy_admin_list_roles($pid) {
|
||||||
|
$roles = array();
|
||||||
|
$result = db_query('SELECT r.name FROM {role} r INNER JOIN {password_policy_role} p ON r.rid = p.rid WHERE p.pid = %d', $pid);
|
||||||
|
while ($row = db_fetch_object($result)) {
|
||||||
|
$roles[] = $row->name;
|
||||||
|
}
|
||||||
|
return $roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of the password policies.
|
||||||
|
*/
|
||||||
|
function password_policy_admin_list() {
|
||||||
|
$form = array();
|
||||||
|
$options = array();
|
||||||
|
$enabled = array();
|
||||||
|
$result = db_query('SELECT pid, name, enabled, description, created, weight FROM {password_policy} ORDER BY weight');
|
||||||
|
while ($row = db_fetch_array($result)) {
|
||||||
|
$pid = $row['pid'];
|
||||||
|
$options[$pid] = $row['enabled'] ? format_date($row['created'], 'medium') : '';
|
||||||
|
if ($row['enabled']) {
|
||||||
|
$enabled[] = $pid;
|
||||||
|
}
|
||||||
|
$form[$pid]['name'] = array('#value' => check_plain($row['name']));
|
||||||
|
$form[$pid]['roles'] = array('#value' => theme('item_list', _password_policy_admin_list_roles($pid)));
|
||||||
|
$form['weight'][$pid] = array('#type' => 'weight', '#default_value' => $row['weight']);
|
||||||
|
$form[$pid]['view'] = array('#value' => l(t('view'), 'admin/settings/password_policy/' . $pid));
|
||||||
|
$form[$pid]['edit'] = array('#value' => l(t('edit'), 'admin/settings/password_policy/' . $pid . '/edit'));
|
||||||
|
$form[$pid]['delete'] = array('#value' => l(t('delete'), 'admin/settings/password_policy/delete/' . $pid));
|
||||||
|
}
|
||||||
|
$form['weight']['#tree'] = TRUE;
|
||||||
|
$form['enabled'] = array('#type' => 'checkboxes', '#options' => $options, '#default_value' => $enabled);
|
||||||
|
$form['submit'] = array('#type' => 'submit', '#value' => t('Save changes'));
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit hook for the form on the default list view for the password policy
|
||||||
|
* module.
|
||||||
|
*/
|
||||||
|
function password_policy_admin_list_submit($form, &$form_state) {
|
||||||
|
foreach ($form_state['values']['enabled'] as $pid => $enabled) {
|
||||||
|
db_query("UPDATE {password_policy} SET weight = %d WHERE pid = %d", $form_state['values']['weight'][$pid], $pid);
|
||||||
|
// Ensure we don't reset the timestamp on policies that are already
|
||||||
|
// enabled.
|
||||||
|
if ($enabled) {
|
||||||
|
db_query("UPDATE {password_policy} SET enabled = 1, created = %d WHERE pid = %d AND enabled = 0", time(), $pid);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
db_query("UPDATE {password_policy} SET enabled = 0 WHERE pid = %d", $pid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drupal_set_message(t('The changes have been saved.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default view for the password policy.
|
||||||
|
*/
|
||||||
|
function password_policy_admin_view($policy) {
|
||||||
|
$output = check_plain($policy['description']);
|
||||||
|
$header = array(t('Name'), t('Constraint'));
|
||||||
|
$rows = array();
|
||||||
|
$roles = _password_policy_admin_list_roles($policy['pid']);
|
||||||
|
if (!empty($roles)) {
|
||||||
|
$rows[] = array(t('Roles'), theme('item_list', $roles));
|
||||||
|
}
|
||||||
|
if (!empty($policy['expiration'])) {
|
||||||
|
$rows[] = array(t('Expiration'), $policy['expiration']);
|
||||||
|
}
|
||||||
|
if (!empty($policy['warning'])) {
|
||||||
|
$rows[] = array(t('Warning'), check_plain($policy['warning']));
|
||||||
|
}
|
||||||
|
foreach ($policy['policy'] as $key => $val) {
|
||||||
|
$desc = _password_policy_constraint_description($key);
|
||||||
|
$rows[] = array($desc['name'], $val);
|
||||||
|
}
|
||||||
|
if (empty($rows)) {
|
||||||
|
$rows[] = array(array('data' => t('No policies defined.'), 'colspan' => 2));
|
||||||
|
}
|
||||||
|
$output .= theme('table', $header, $rows);
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form display for new or to be edited password policies.
|
||||||
|
*/
|
||||||
|
function password_policy_admin_form($form_state, $policy = NULL) {
|
||||||
|
$form['policy']['name'] = array(
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#title' => t('Name'),
|
||||||
|
'#default_value' => $policy['name'],
|
||||||
|
'#maxlength' => 64,
|
||||||
|
'#required' => TRUE,
|
||||||
|
);
|
||||||
|
$form['policy']['description'] = array(
|
||||||
|
'#type' => 'textarea',
|
||||||
|
'#title' => t('Description'),
|
||||||
|
'#default_value' => $policy['description'],
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['roles'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('Roles'),
|
||||||
|
'#collapsible' => TRUE,
|
||||||
|
'#collapsed' => FALSE
|
||||||
|
);
|
||||||
|
$form['roles']['roles'] = array(
|
||||||
|
'#type' => 'checkboxes',
|
||||||
|
'#title' => t('Roles'),
|
||||||
|
'#options' => user_roles(TRUE),
|
||||||
|
'#default_value' => isset($policy['roles']) ? $policy['roles'] : array(),
|
||||||
|
'#description' => t('Select the roles that this policy will apply to.'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['expiration'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('Expiration'),
|
||||||
|
'#collapsible' => TRUE,
|
||||||
|
'#collapsed' => FALSE
|
||||||
|
);
|
||||||
|
$form['expiration']['expiration'] = array('#type' => 'textfield',
|
||||||
|
'#title' => t('Password Expiration'),
|
||||||
|
'#default_value' => $policy['expiration'],
|
||||||
|
'#size' => 5,
|
||||||
|
'#maxlength' => 5,
|
||||||
|
'#description' => t('The passwords will expire after this number of days. The users with expired passwords will be blocked. Leaving this field empty won\'t put any password expiration constraints.'),
|
||||||
|
);
|
||||||
|
$form['expiration']['warning'] = array('#type' => 'textfield',
|
||||||
|
'#title' => t('Password Expiration Warning'),
|
||||||
|
'#default_value' => $policy['warning'],
|
||||||
|
'#size' => 10,
|
||||||
|
'#description' => t('The comma separated list of days. The warning about expiration of the password will be sent out on those days before the expiration. Leaving this field empty won\'t send out or display any warnings.'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['constraints'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('Constraints'),
|
||||||
|
'#collapsible' => TRUE,
|
||||||
|
'#collapsed' => FALSE
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (_password_policy_constraints() as $constraint) {
|
||||||
|
$desc = _password_policy_constraint_description($constraint);
|
||||||
|
$form['constraints']['constraint_' . $constraint] = array(
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#size' => 5,
|
||||||
|
'#default_value' => isset($policy['policy'][$constraint]) ? $policy['policy'][$constraint] : NULL,
|
||||||
|
'#maxlength' => 2,
|
||||||
|
'#title' => filter_xss($desc['name']),
|
||||||
|
'#description' => filter_xss($desc['description']),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$form['submit'] = array(
|
||||||
|
'#type' => 'submit',
|
||||||
|
'#value' => is_array($policy) ? t('Save') : t('Create'),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($policy) {
|
||||||
|
$form['delete'] = array(
|
||||||
|
'#type' => 'submit',
|
||||||
|
'#value' => t('Delete'),
|
||||||
|
);
|
||||||
|
$form['pid'] = array(
|
||||||
|
'#type' => 'hidden',
|
||||||
|
'#value' => $policy['pid'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form validation hook for new or edited password policies.
|
||||||
|
*/
|
||||||
|
function password_policy_admin_form_validate($form, &$form_state) {
|
||||||
|
$roles = array_filter($form_state['values']['roles']);
|
||||||
|
if (empty($roles)) {
|
||||||
|
form_set_error('roles', t('You must select at least one role for a policy to apply to.'));
|
||||||
|
}
|
||||||
|
if (!empty($form_state['values']['warning']) && !preg_match("/^[0-9,]+$/", $form_state['values']['warning'])) {
|
||||||
|
form_set_error('warning', t('Warning must only contain digits and commas'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form submission hook for new or edited password policies.
|
||||||
|
*/
|
||||||
|
function password_policy_admin_form_submit($form, &$form_state) {
|
||||||
|
$op = $form_state['values']['op'];
|
||||||
|
|
||||||
|
if ($op == t('Delete')) {
|
||||||
|
drupal_goto('admin/settings/password_policy/delete/' . $form_state['values']['pid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$policy = array();
|
||||||
|
foreach ($form_state['values'] as $key => $value) {
|
||||||
|
// If we have no form value, then we have no constraint to set.
|
||||||
|
if (!is_array($value)) { //dodge issues with roles array
|
||||||
|
$value = trim($value);
|
||||||
|
if ($value != "" && preg_match("/^constraint_/", $key)) {
|
||||||
|
$policy[substr($key, 11)] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we have an pid, update, else save.
|
||||||
|
if (isset($form_state['values']['pid'])) {
|
||||||
|
db_query("UPDATE {password_policy} SET name = '%s', description = '%s', policy = '%s', expiration = %d, warning = '%s' WHERE pid = %d", $form_state['values']['name'], $form_state['values']['description'], serialize($policy), trim($form_state['values']['expiration']), str_replace(' ', '', $form_state['values']['warning']), $form_state['values']['pid']);
|
||||||
|
drupal_set_message(t('Policy %name has been updated.', array('%name' => $form_state['values']['name'])));
|
||||||
|
watchdog('password_policy', 'Policy %name updated.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE, l(t('edit'), 'admin/settings/password_policy/' . $form_state['values']['pid'] . '/edit'));
|
||||||
|
$pid = $form_state['values']['pid'];
|
||||||
|
db_query("DELETE FROM {password_policy_role} WHERE pid = %d", $pid);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
db_query("INSERT INTO {password_policy} (name, description, enabled, policy, expiration, warning) VALUES ('%s', '%s', %d, '%s', %d, '%s')", $form_state['values']['name'], $form_state['values']['description'], 0, serialize($policy), trim($form_state['values']['expiration']), str_replace(' ', '', $form_state['values']['warning']));
|
||||||
|
$pid = db_last_insert_id('password_policy', 'pid');
|
||||||
|
drupal_set_message(t('Policy %name has been created.', array('%name' => $form_state['values']['name'])));
|
||||||
|
watchdog('password_policy', 'New policy %name created.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE, l(t('edit'), 'admin/settings/password_policy/' . $pid . '/edit'));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (array_filter($form_state['values']['roles']) as $rid => $enabled) {
|
||||||
|
db_query("INSERT INTO {password_policy_role} (pid, rid) VALUES (%d, %d)", $pid, $rid);
|
||||||
|
}
|
||||||
|
|
||||||
|
drupal_goto('admin/settings/password_policy/list');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirmation form for the deletion of a password policy. Deletion takes
|
||||||
|
* place in password_policy_admin_delete_submit().
|
||||||
|
*/
|
||||||
|
function password_policy_admin_delete($form_state, $pid) {
|
||||||
|
if (is_numeric($pid) && $policy = _password_policy_load_policy_by_pid($pid)) {
|
||||||
|
$form['pid'] = array('#type' => 'hidden', '#value' => $policy['pid']);
|
||||||
|
|
||||||
|
return confirm_form($form, t('Are you sure you want to delete the policy %name?', array('%name' => $policy['name'])), 'admin/settings/password_policy/list', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
drupal_not_found();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit hook for the delete policy operation.
|
||||||
|
*/
|
||||||
|
function password_policy_admin_delete_submit($form, &$form_state) {
|
||||||
|
$pid = $form_state['values']['pid'];
|
||||||
|
$policy = _password_policy_load_policy_by_pid($pid);
|
||||||
|
|
||||||
|
db_query("DELETE FROM {password_policy} WHERE pid = %d", $pid);
|
||||||
|
db_query("DELETE FROM {password_policy_role} WHERE pid = %d", $pid);
|
||||||
|
drupal_set_message(t('Password policy %policy was deleted.', array('%policy' => $policy['name'])));
|
||||||
|
watchdog('password_policy', 'Policy %name was deleted.', array('%name' => $policy['name']), WATCHDOG_NOTICE);
|
||||||
|
drupal_goto('admin/settings/password_policy/list');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forced password change form.
|
||||||
|
*/
|
||||||
|
function password_policy_password_change_settings() {
|
||||||
|
$form['password_policy_new_login_change'] = array(
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Force password change on first-time login'),
|
||||||
|
'#default_value' => variable_get('password_policy_new_login_change', 0),
|
||||||
|
);
|
||||||
|
|
||||||
|
$roles = user_roles(TRUE);
|
||||||
|
$form['password_policy_force_change_roles'] = array(
|
||||||
|
'#type' => 'checkboxes',
|
||||||
|
'#options' => $roles,
|
||||||
|
'#title' => t('Force users in the following roles to change their password'),
|
||||||
|
'#description' => t('Users who are not logged in will be required to change their password immediately upon login. Users who are currently logged in will be required to change their password upon their next page request, but after changing their password will be redirected back to the page they were attempting to access.'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['password_policy_exclude_pages'] = array(
|
||||||
|
'#title' => t('Page Exclusion List'),
|
||||||
|
'#type' => 'textarea',
|
||||||
|
'#description' => t('The user will be able to access these pages without changing their password. This should always include the logout path.'),
|
||||||
|
'#default_value' => variable_get('password_policy_exclude_pages', 'logout'),
|
||||||
|
'#wysiwyg' => FALSE,
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['submit'] = array(
|
||||||
|
'#type' => 'submit',
|
||||||
|
'#value' => t('Submit'),
|
||||||
|
);
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit hook for forced password change form.
|
||||||
|
*/
|
||||||
|
function password_policy_password_change_settings_submit($form, &$form_state) {
|
||||||
|
global $user;
|
||||||
|
$selected_roles = array();
|
||||||
|
variable_set('password_policy_new_login_change', $form_state['values']['password_policy_new_login_change']);
|
||||||
|
variable_set('password_policy_exclude_pages', $form_state['values']['password_policy_exclude_pages']);
|
||||||
|
if ($form_state['values']['password_policy_new_login_change'] == 1) {
|
||||||
|
watchdog('password policy', t('New user accounts must change password on new login enabled by !admin', array('!admin' => $user->name)), array(), WATCHDOG_NOTICE);
|
||||||
|
}
|
||||||
|
($form_state['values']['password_policy_new_login_change']) ? drupal_set_message(t('New users will be required to change their password on first-time login.')) : drupal_set_message(t('New users will not be required to change their pasword on first-time login.'));
|
||||||
|
foreach ($form_state['values']['password_policy_force_change_roles'] as $role) {
|
||||||
|
// skip over null values returned by unselected roles
|
||||||
|
if ($role == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$uids = array();
|
||||||
|
// special handling for authenticated users role
|
||||||
|
// since this role makes no entries in the users_roles table
|
||||||
|
if ($role == 2) {
|
||||||
|
// no point in flagging Anonymous since they can't log in anyway
|
||||||
|
$db_uids = db_query('SELECT uid FROM {users} WHERE uid <> 0');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$db_uids = db_query('SELECT uid FROM {users_roles} WHERE rid = %d', $role);
|
||||||
|
}
|
||||||
|
while ($uid = db_result($db_uids)) {
|
||||||
|
if (($uid == 1 && variable_get('password_policy_admin', 0)) || $uid > 1) {
|
||||||
|
$uids[] = $uid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($uids)) {
|
||||||
|
$sql = 'UPDATE {password_policy_force_change} SET force_change = 1 WHERE uid IN (' . db_placeholders($uids, 'int') . ')';
|
||||||
|
db_query($sql, $uids);
|
||||||
|
}
|
||||||
|
$selected_roles[] = $role;
|
||||||
|
}
|
||||||
|
if (count($selected_roles)) {
|
||||||
|
$roles = user_roles(TRUE);
|
||||||
|
$list = array();
|
||||||
|
foreach ($selected_roles as $sr) {
|
||||||
|
$list[] = $roles[$sr];
|
||||||
|
}
|
||||||
|
$list = implode(', ', $list);
|
||||||
|
drupal_set_message(t('Users in the following roles will be required to immediately change their password: %list', array('%list' => $list)), 'status');
|
||||||
|
watchdog('password policy', t('!admin has flagged users in the following roles to immediately change their password: %list', array('%list' => $list, '!admin' => $user->name)), array(), WATCHDOG_NOTICE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
drupal_set_message(t('No roles were selected.'));
|
||||||
|
}
|
||||||
|
}
|
11
sites/all/modules/password_policy/password_policy.info
Normal file
11
sites/all/modules/password_policy/password_policy.info
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
name = Password policy
|
||||||
|
description = The password policy module allows you to enforce a specific level of password complexity for the user passwords on the system.
|
||||||
|
package = Security
|
||||||
|
core = 6.x
|
||||||
|
|
||||||
|
; Information added by Drupal.org packaging script on 2015-03-31
|
||||||
|
version = "6.x-1.11"
|
||||||
|
core = "6.x"
|
||||||
|
project = "password_policy"
|
||||||
|
datestamp = "1427843284"
|
||||||
|
|
361
sites/all/modules/password_policy/password_policy.install
Normal file
361
sites/all/modules/password_policy/password_policy.install
Normal file
|
@ -0,0 +1,361 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* File module installation and upgrade code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_schema().
|
||||||
|
*/
|
||||||
|
function password_policy_schema() {
|
||||||
|
return array(
|
||||||
|
'password_policy' => array(
|
||||||
|
'description' => t("Stores password policies."),
|
||||||
|
'fields' => array(
|
||||||
|
'pid' => array(
|
||||||
|
'description' => t("Primary Key: Unique password policy ID."),
|
||||||
|
'type' => 'serial',
|
||||||
|
'not null' => TRUE,
|
||||||
|
),
|
||||||
|
'name' => array(
|
||||||
|
'description' => t("The name of the policy."),
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 64,
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => '',
|
||||||
|
),
|
||||||
|
'description' => array(
|
||||||
|
'description' => t("The description of the policy."),
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 255,
|
||||||
|
'default' => '',
|
||||||
|
),
|
||||||
|
'enabled' => array(
|
||||||
|
'description' => t("Whether the policy is enabled."),
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
'size' => 'tiny',
|
||||||
|
),
|
||||||
|
'policy' => array(
|
||||||
|
'description' => t("The policy's serialized data."),
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 1024,
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => '',
|
||||||
|
),
|
||||||
|
'created' => array(
|
||||||
|
'description' => t("Timestamp for when the policy was created."),
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
),
|
||||||
|
'expiration' => array(
|
||||||
|
'description' => t("The passwords will expire after this number of days."),
|
||||||
|
'type' => 'int',
|
||||||
|
),
|
||||||
|
'warning' => array(
|
||||||
|
'description' => t("Comma separated list of days when warning is sent out."),
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 64,
|
||||||
|
),
|
||||||
|
'weight' => array(
|
||||||
|
'description' => t("Weight of the policy, used to order active policies."),
|
||||||
|
'type' => 'int',
|
||||||
|
'size' => 'tiny',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('pid'),
|
||||||
|
'unique keys' => array(
|
||||||
|
'name' => array('name'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'password_policy_history' => array(
|
||||||
|
'description' => t("Stores users' old password hashes."),
|
||||||
|
'fields' => array(
|
||||||
|
'pid' => array(
|
||||||
|
'description' => t("Primary Key: Unique password policy users ID."),
|
||||||
|
'type' => 'serial',
|
||||||
|
'not null' => TRUE,
|
||||||
|
),
|
||||||
|
'uid' => array(
|
||||||
|
'description' => t("User's {users}.uid."),
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
),
|
||||||
|
'pass' => array(
|
||||||
|
'description' => t("User's password (hashed)."),
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 128,
|
||||||
|
'not null' => TRUE,
|
||||||
|
),
|
||||||
|
'created' => array(
|
||||||
|
'description' => t("Timestamp for when the policy was created."),
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('pid'),
|
||||||
|
'indexes' => array('uid' => array('uid')),
|
||||||
|
),
|
||||||
|
'password_policy_expiration' => array(
|
||||||
|
'description' => t('Stores users password expiration data.'),
|
||||||
|
'fields' => array(
|
||||||
|
'pid' => array(
|
||||||
|
'description' => t("Primary Key: Unique password policy expirations ID."),
|
||||||
|
'type' => 'serial',
|
||||||
|
'not null' => TRUE,
|
||||||
|
),
|
||||||
|
'uid' => array(
|
||||||
|
'description' => t("User's {users}.uid."),
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
),
|
||||||
|
'warning' => array(
|
||||||
|
'description' => t("Timestamp for when the warning was shown."),
|
||||||
|
'type' => 'int',
|
||||||
|
),
|
||||||
|
'blocked' => array(
|
||||||
|
'description' => t("Timestamp for when the user was blocked."),
|
||||||
|
'type' => 'int',
|
||||||
|
),
|
||||||
|
'unblocked' => array(
|
||||||
|
'description' => t("Timestamp for when the user was unblocked."),
|
||||||
|
'type' => 'int',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('pid'),
|
||||||
|
'indexes' => array('uid' => array('uid')),
|
||||||
|
),
|
||||||
|
'password_policy_force_change' => array(
|
||||||
|
'description' => t('Forced password reset status.'),
|
||||||
|
'fields' => array(
|
||||||
|
'uid' => array('type' => 'int', 'not null' => TRUE),
|
||||||
|
'force_change' => array('type' => 'int', 'default' => 0),
|
||||||
|
),
|
||||||
|
'indexes' => array('uid' => array('uid')),
|
||||||
|
),
|
||||||
|
'password_policy_role' => array(
|
||||||
|
'description' => t("Links policies with roles."),
|
||||||
|
'fields' => array(
|
||||||
|
'rid' => array(
|
||||||
|
'description' => t("Role ID."),
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
),
|
||||||
|
'pid' => array(
|
||||||
|
'description' => t("Policy ID."),
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
),
|
||||||
|
'name' => array(
|
||||||
|
'description' => t("The name of the policy."),
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 64,
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => '',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('rid', 'pid'),
|
||||||
|
'unique keys' => array(
|
||||||
|
'name' => array('rid', 'name'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_enable().
|
||||||
|
*/
|
||||||
|
function password_policy_enable() {
|
||||||
|
drupal_set_message(t('Password policy module successfully installed. Please review the available <a href="@settings">configuration settings</a>.', array('@settings' => url('admin/settings/password_policy'))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_install().
|
||||||
|
*/
|
||||||
|
function password_policy_install() {
|
||||||
|
drupal_install_schema('password_policy');
|
||||||
|
db_query('INSERT INTO {password_policy_force_change} (uid) SELECT DISTINCT uid FROM {users} WHERE uid > 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_uninstall().
|
||||||
|
*/
|
||||||
|
function password_policy_uninstall() {
|
||||||
|
drupal_uninstall_schema('password_policy');
|
||||||
|
variable_del('password_policy_admin');
|
||||||
|
variable_del('password_policy_begin');
|
||||||
|
variable_del('password_policy_block');
|
||||||
|
variable_del('password_policy_show_restrictions');
|
||||||
|
variable_del('password_policy_warning_subject');
|
||||||
|
variable_del('password_policy_warning_body');
|
||||||
|
variable_del('password_policy_new_login_change');
|
||||||
|
variable_del('password_policy_change_url');
|
||||||
|
}
|
||||||
|
|
||||||
|
function password_policy_update_6000() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
db_add_field($ret, 'password_policy', 'weight', array(
|
||||||
|
'description' => t("Weight of the policy, used to order active policies."),
|
||||||
|
'type' => 'int',
|
||||||
|
'size' => 'tiny',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
));
|
||||||
|
|
||||||
|
db_create_table($ret, 'password_policy_role', array(
|
||||||
|
'description' => t("Links policies with roles."),
|
||||||
|
'fields' => array(
|
||||||
|
'rid' => array(
|
||||||
|
'description' => t("Role ID."),
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
),
|
||||||
|
'pid' => array(
|
||||||
|
'description' => t("Policy ID."),
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('rid', 'pid'),
|
||||||
|
));
|
||||||
|
|
||||||
|
// Ensure existing policies are active for all roles.
|
||||||
|
$result = db_query("SELECT pid FROM {password_policy}");
|
||||||
|
while ($row = db_fetch_object($result)) {
|
||||||
|
$ret[] = update_sql("INSERT INTO {password_policy_role} (pid, rid) VALUES (" . $row->pid . ", " . DRUPAL_AUTHENTICATED_RID . ")");
|
||||||
|
$ret[] = update_sql("INSERT INTO {password_policy_role} (pid, rid) VALUES (" . $row->pid . ", " . DRUPAL_ANONYMOUS_RID . ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
function password_policy_update_6001() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
db_create_table($ret, 'password_policy_force_change', array(
|
||||||
|
'description' => t('Forced password reset status.'),
|
||||||
|
'fields' => array(
|
||||||
|
'uid' => array('type' => 'int', 'not null' => TRUE),
|
||||||
|
'force_change' => array('type' => 'int', 'default' => 0),
|
||||||
|
),
|
||||||
|
'indexes' => array('uid' => array('uid')),
|
||||||
|
));
|
||||||
|
$ret[] = update_sql('INSERT INTO {password_policy_force_change} (uid) SELECT DISTINCT uid FROM {users} WHERE uid > 0');
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix for http://drupal.org/node/583902.
|
||||||
|
*/
|
||||||
|
function password_policy_update_6002() {
|
||||||
|
$ret = array();
|
||||||
|
db_change_field($ret, 'password_policy', 'policy', 'policy', array(
|
||||||
|
'description' => t('The serialized policy data'),
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 1024,
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => '',
|
||||||
|
));
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure name on password_policy is unique for exportables (features)
|
||||||
|
*/
|
||||||
|
function password_policy_update_6003() {
|
||||||
|
$ret = array();
|
||||||
|
db_add_unique_key($ret, 'password_policy', 'name', array('name'));
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure name column on password_policy_role for exportables (features)
|
||||||
|
*/
|
||||||
|
function password_policy_update_6004() {
|
||||||
|
$ret = array();
|
||||||
|
db_add_field($ret, 'password_policy_role', 'name',
|
||||||
|
array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''));
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure name column on password_policy_role is set with corrsponding name
|
||||||
|
*/
|
||||||
|
function password_policy_update_6005() {
|
||||||
|
$ret = array();
|
||||||
|
// update name based on name from password_policy table where pid's match
|
||||||
|
// update password_policy_role pr, password_policy
|
||||||
|
// set pr.name = pp.name
|
||||||
|
// where pr.pid = pp.pid;
|
||||||
|
$ret[] = update_sql("UPDATE {password_policy_role} pr SET name = (SELECT name FROM {password_policy} pp WHERE pr.pid = pp.pid)");
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add unique key on password_policy_role for exportables (rid,name)
|
||||||
|
*/
|
||||||
|
function password_policy_update_6006() {
|
||||||
|
$ret = array();
|
||||||
|
// could drop past primary key, and add new primary key but this
|
||||||
|
// works for now leaving old primary in place
|
||||||
|
db_add_unique_key($ret, 'password_policy_role', 'name', array('rid', 'name'));
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify of change to username constraint behavior.
|
||||||
|
*/
|
||||||
|
function password_policy_update_6100() {
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'success' => TRUE,
|
||||||
|
'query' => t('The username constraint has changed to disallow passwords containing the username in addition to passwords matching the username.'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase length of {password_policy_history}.pass to support phpass.
|
||||||
|
*/
|
||||||
|
function password_policy_update_6101() {
|
||||||
|
$ret = array();
|
||||||
|
db_change_field($ret, 'password_policy_history', 'pass', 'pass', array(
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 128,
|
||||||
|
'not null' => TRUE,
|
||||||
|
));
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase module weight to support phpass.
|
||||||
|
*/
|
||||||
|
function password_policy_update_6102() {
|
||||||
|
$ret = array();
|
||||||
|
$ret[] = update_sql("UPDATE {system} SET weight = 1 WHERE type = 'module' AND name = 'password_policy'");
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset module weight to 0.
|
||||||
|
*
|
||||||
|
* A custom module weight is no longer needed to support phpass.
|
||||||
|
*/
|
||||||
|
function password_policy_update_6103() {
|
||||||
|
$ret = array();
|
||||||
|
$ret[] = update_sql("UPDATE {system} SET weight = 0 WHERE type = 'module' AND name = 'password_policy'");
|
||||||
|
return $ret;
|
||||||
|
}
|
113
sites/all/modules/password_policy/password_policy.js
Normal file
113
sites/all/modules/password_policy/password_policy.js
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Attaches handlers to evaluate the strength of any password fields and to
|
||||||
|
* check that its confirmation is correct.
|
||||||
|
*/
|
||||||
|
Drupal.behaviors.password = function(context) {
|
||||||
|
var translate = Drupal.settings.password_policy;
|
||||||
|
$("input.password-field:not(.password-processed)", context).each(function() {
|
||||||
|
var passwordInput = $(this).addClass('password-processed');
|
||||||
|
var parent = $(this).parent();
|
||||||
|
// Wait this number of milliseconds before checking password.
|
||||||
|
var monitorDelay = 700;
|
||||||
|
|
||||||
|
// Add the password strength layers.
|
||||||
|
$(this).after('<span class="password-strength"><span class="password-title">'+ translate.strengthTitle +'</span> <span class="password-result"></span></span>').parent();
|
||||||
|
var passwordStrength = $("span.password-strength", parent);
|
||||||
|
var passwordResult = $("span.password-result", passwordStrength);
|
||||||
|
parent.addClass("password-parent");
|
||||||
|
|
||||||
|
// Add the password confirmation layer.
|
||||||
|
var outerItem = $(this).parent().parent();
|
||||||
|
$("input.password-confirm", outerItem).after('<span class="password-confirm">'+ translate["confirmTitle"] +' <span></span></span>').parent().addClass("confirm-parent");
|
||||||
|
var confirmInput = $("input.password-confirm", outerItem);
|
||||||
|
var confirmResult = $("span.password-confirm", outerItem);
|
||||||
|
var confirmChild = $("span", confirmResult);
|
||||||
|
|
||||||
|
// Add the description box at the end.
|
||||||
|
$(confirmInput).parent().after('<div class="password-description"></div>');
|
||||||
|
var passwordDescription = $("div.password-description", $(this).parent().parent()).hide();
|
||||||
|
|
||||||
|
// Check the password fields.
|
||||||
|
var passwordCheck = function () {
|
||||||
|
// Remove timers for a delayed check if they exist.
|
||||||
|
if (this.timer) {
|
||||||
|
clearTimeout(this.timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify that there is a password to check.
|
||||||
|
if (!passwordInput.val()) {
|
||||||
|
passwordStrength.css({ visibility: "hidden" });
|
||||||
|
passwordDescription.hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Evaluate password strength.
|
||||||
|
|
||||||
|
var result = Drupal.evaluatePasswordStrength(passwordInput.val());
|
||||||
|
passwordResult.html(result.strength == "" ? "" : translate[result.strength +"Strength"]);
|
||||||
|
|
||||||
|
// Map the password strength to the relevant drupal CSS class.
|
||||||
|
var classMap = { low: "error", medium: "warning", high: "ok" };
|
||||||
|
var newClass = classMap[result.strength] || "";
|
||||||
|
|
||||||
|
// Remove the previous styling if any exists; add the new class.
|
||||||
|
if (this.passwordClass) {
|
||||||
|
passwordResult.removeClass(this.passwordClass);
|
||||||
|
passwordDescription.removeClass(this.passwordClass);
|
||||||
|
}
|
||||||
|
passwordDescription.html(result.message);
|
||||||
|
passwordResult.addClass(newClass);
|
||||||
|
if (result.strength == "high") {
|
||||||
|
passwordDescription.hide();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
passwordDescription.addClass(newClass);
|
||||||
|
}
|
||||||
|
this.passwordClass = newClass;
|
||||||
|
|
||||||
|
// Check that password and confirmation match.
|
||||||
|
|
||||||
|
// Hide the result layer if confirmation is empty, otherwise show the layer.
|
||||||
|
confirmResult.css({ visibility: (confirmInput.val() == "" ? "hidden" : "visible") });
|
||||||
|
|
||||||
|
var success = passwordInput.val() == confirmInput.val();
|
||||||
|
|
||||||
|
// Remove the previous styling if any exists.
|
||||||
|
if (this.confirmClass) {
|
||||||
|
confirmChild.removeClass(this.confirmClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill in the correct message and set the class accordingly.
|
||||||
|
var confirmClass = success ? "ok" : "error";
|
||||||
|
confirmChild.html(translate["confirm"+ (success ? "Success" : "Failure")]).addClass(confirmClass);
|
||||||
|
this.confirmClass = confirmClass;
|
||||||
|
|
||||||
|
// Show the indicator and tips.
|
||||||
|
passwordStrength.css({ visibility: "visible" });
|
||||||
|
passwordDescription.show();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Do a delayed check on the password fields.
|
||||||
|
var passwordDelayedCheck = function() {
|
||||||
|
// Postpone the check since the user is most likely still typing.
|
||||||
|
if (this.timer) {
|
||||||
|
clearTimeout(this.timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// When the user clears the field, hide the tips immediately.
|
||||||
|
if (!passwordInput.val()) {
|
||||||
|
passwordStrength.css({ visibility: "hidden" });
|
||||||
|
passwordDescription.hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Schedule the actual check.
|
||||||
|
this.timer = setTimeout(passwordCheck, monitorDelay);
|
||||||
|
};
|
||||||
|
// Monitor keyup and blur events.
|
||||||
|
// Blur must be used because a mouse paste does not trigger keyup.
|
||||||
|
passwordInput.keyup(passwordDelayedCheck).blur(passwordCheck);
|
||||||
|
confirmInput.keyup(passwordDelayedCheck).blur(passwordCheck);
|
||||||
|
});
|
||||||
|
};
|
1049
sites/all/modules/password_policy/password_policy.module
Normal file
1049
sites/all/modules/password_policy/password_policy.module
Normal file
File diff suppressed because it is too large
Load diff
43
sites/all/modules/password_policy/password_policy.theme.inc
Normal file
43
sites/all/modules/password_policy/password_policy.theme.inc
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Theme callback file for the password_policy module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Password policy admin themes */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom theme for rendering a radio list of defined policies.
|
||||||
|
* This layout is based on a similar layout found in the "filter" module.
|
||||||
|
*
|
||||||
|
* @ingroup themeable
|
||||||
|
*/
|
||||||
|
function theme_password_policy_admin_list($form) {
|
||||||
|
$rows = array();
|
||||||
|
foreach ($form as $pid => $element) {
|
||||||
|
if (isset($element['edit']) && is_array($element['edit'])) {
|
||||||
|
$rows[] = array(
|
||||||
|
check_plain($form[$pid]['name']['#value']),
|
||||||
|
$form[$pid]['roles']['#value'],
|
||||||
|
drupal_render($form['enabled'][$pid]),
|
||||||
|
drupal_render($form['weight'][$pid]),
|
||||||
|
drupal_render($form[$pid]['view']),
|
||||||
|
drupal_render($form[$pid]['edit']),
|
||||||
|
drupal_render($form[$pid]['delete'])
|
||||||
|
);
|
||||||
|
unset($form[$pid]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($rows)) {
|
||||||
|
$rows[] = array(array('data' => t('No policies defined.'), 'colspan' => 5));
|
||||||
|
unset($form['submit']);
|
||||||
|
unset($form['clear']);
|
||||||
|
}
|
||||||
|
$header = array(t('Policy'), t('Roles'), t('Enabled'), t('Weight'), array('data' => t('Operations'), 'colspan' => 3));
|
||||||
|
$output = theme('table', $header, $rows);
|
||||||
|
$output .= drupal_render($form);
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
456
sites/all/modules/password_policy/tests/password_policy.test
Normal file
456
sites/all/modules/password_policy/tests/password_policy.test
Normal file
|
@ -0,0 +1,456 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Unit tests for Password policy module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PasswordPolicyTest extends DrupalWebTestCase {
|
||||||
|
public static function getInfo() {
|
||||||
|
return array(
|
||||||
|
'name' => 'Constraints Test',
|
||||||
|
'description' => 'Assure that password constraints work.',
|
||||||
|
'group' => 'Password Policy',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
if (defined('USER_LOAD_PHPASS_PATCHED')) {
|
||||||
|
parent::setUp('password_policy', 'phpass');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
parent::setUp('password_policy');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testUppercaseConstraint() {
|
||||||
|
module_load_include('inc', 'password_policy', 'constraints/constraint_uppercase');
|
||||||
|
$constraint = 2;
|
||||||
|
$uid = 0;
|
||||||
|
$pass = 'Abc';
|
||||||
|
$result = password_policy_constraint_uppercase_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertFalse($result, 'One uppercase letter in the uppercase constraint with param 2');
|
||||||
|
$pass = 'ABc';
|
||||||
|
$result = password_policy_constraint_uppercase_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'Two uppercase letters in the uppercase constraint with param 2');
|
||||||
|
$pass = 'ABC';
|
||||||
|
$result = password_policy_constraint_uppercase_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'Three uppercase letters in the uppercase constraint with param 2');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLowercaseConstraint() {
|
||||||
|
module_load_include('inc', 'password_policy', 'constraints/constraint_lowercase');
|
||||||
|
$constraint = 2;
|
||||||
|
$uid = 0;
|
||||||
|
$pass = 'Abc';
|
||||||
|
$result = password_policy_constraint_lowercase_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'One uppercase letter in the lowercase constraint with param 2');
|
||||||
|
$pass = 'ABc';
|
||||||
|
$result = password_policy_constraint_lowercase_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertFalse($result, 'Two uppercase letters in the lowercase constraint with param 2');
|
||||||
|
$pass = 'ABC';
|
||||||
|
$result = password_policy_constraint_lowercase_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertFalse($result, 'Three uppercase letters in the lowercase constraint with param 2');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLetterConstraint() {
|
||||||
|
module_load_include('inc', 'password_policy', 'constraints/constraint_letter');
|
||||||
|
$constraint = 2;
|
||||||
|
$uid = 0;
|
||||||
|
$pass = 'a12';
|
||||||
|
$result = password_policy_constraint_letter_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertFalse($result, 'One lowercase letter in the letter constraint with param 2');
|
||||||
|
$pass = 'aB1';
|
||||||
|
$result = password_policy_constraint_letter_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'One lowercase and one uppercase letter in the letter constraint with param 2');
|
||||||
|
$pass = 'abC';
|
||||||
|
$result = password_policy_constraint_letter_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'Two lowercase and one uppercase letter in the letter constraint with param 2');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testDigitConstraint() {
|
||||||
|
module_load_include('inc', 'password_policy', 'constraints/constraint_digit');
|
||||||
|
$constraint = 2;
|
||||||
|
$uid = 0;
|
||||||
|
$pass = '1ab';
|
||||||
|
$result = password_policy_constraint_digit_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertFalse($result, 'One digit in the digit constraint with param 2');
|
||||||
|
$pass = '12a';
|
||||||
|
$result = password_policy_constraint_digit_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'Two digits in the digit constraint with param 2');
|
||||||
|
$pass = '123';
|
||||||
|
$result = password_policy_constraint_digit_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'Three digits in the digit constraint with param 2');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLengthConstraint() {
|
||||||
|
module_load_include('inc', 'password_policy', 'constraints/constraint_length');
|
||||||
|
$constraint = 6;
|
||||||
|
$uid = 0;
|
||||||
|
$pass = 'abcde';
|
||||||
|
$result = password_policy_constraint_length_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertFalse($result, 'Five characters password in the length constraint with param 6');
|
||||||
|
$pass = 'abcdef';
|
||||||
|
$result = password_policy_constraint_length_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'Six characters password in the length constraint with param 6');
|
||||||
|
$pass = 'abcdefg';
|
||||||
|
$result = password_policy_constraint_length_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'Seven characters password in the length constraint with param 6');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testAlphanumericConstraint() {
|
||||||
|
module_load_include('inc', 'password_policy', 'constraints/constraint_alphanumeric');
|
||||||
|
$constraint = 2;
|
||||||
|
$uid = 0;
|
||||||
|
$pass = '1$%';
|
||||||
|
$result = password_policy_constraint_alphanumeric_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertFalse($result, 'One digit and no letter in the alphanumeric constraint with param 2');
|
||||||
|
$pass = '1a#';
|
||||||
|
$result = password_policy_constraint_alphanumeric_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'One digit and one letter in the alphanumeric constraint with param 2');
|
||||||
|
$pass = '1ab';
|
||||||
|
$result = password_policy_constraint_alphanumeric_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'One digit ant two letters in the alphanumeric constraint with param 2');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testPunctuationConstraint() {
|
||||||
|
module_load_include('inc', 'password_policy', 'constraints/constraint_punctuation');
|
||||||
|
$constraint = 2;
|
||||||
|
$uid = 0;
|
||||||
|
$pass = '%1a';
|
||||||
|
$result = password_policy_constraint_punctuation_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertFalse($result, 'One punctuation character in the punctuation constraint with param 2');
|
||||||
|
$pass = '%^a';
|
||||||
|
$result = password_policy_constraint_punctuation_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'Two punctuation character in the punctuation constraint with param 2');
|
||||||
|
$pass = '%^&';
|
||||||
|
$result = password_policy_constraint_punctuation_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'Three punctuation character in the punctuation constraint with param 2');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testComplexityConstraint() {
|
||||||
|
module_load_include('inc', 'password_policy', 'constraints/constraint_complexity');
|
||||||
|
$constraint = 2;
|
||||||
|
$uid = 0;
|
||||||
|
$pass = 'abc';
|
||||||
|
$result = password_policy_constraint_complexity_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertFalse($result, 'Three letters in the type constraint with param 2');
|
||||||
|
$pass = 'a1c';
|
||||||
|
$result = password_policy_constraint_complexity_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'Two letters and one digit in the type constraint with param 2');
|
||||||
|
$pass = 'a1&';
|
||||||
|
$result = password_policy_constraint_complexity_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'One letter, one digit and one punctuation in the type constraint with param 2');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testUsernameConstraint() {
|
||||||
|
module_load_include('inc', 'password_policy', 'constraints/constraint_username');
|
||||||
|
$constraint = 2;
|
||||||
|
$user = $this->drupalCreateUser();
|
||||||
|
$name = $this->randomName();
|
||||||
|
$result = password_policy_constraint_username_validate($name, $constraint, $user->uid);
|
||||||
|
$this->assertTrue($result, 'Random string in the username constraint');
|
||||||
|
$result = password_policy_constraint_username_validate($user->name, $constraint, $user->uid);
|
||||||
|
$this->assertFalse($result, 'Username in the username constraint');
|
||||||
|
$result = password_policy_constraint_username_validate('foo' . $user->name . 'bar', $constraint, $user->uid);
|
||||||
|
$this->assertFalse($result, 'String containing username in the username constraint');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testHistoryConstraint() {
|
||||||
|
module_load_include('inc', 'password_policy', 'constraints/constraint_history');
|
||||||
|
// Log in
|
||||||
|
$user = $this->drupalCreateUser(array('administer site configuration'));
|
||||||
|
$this->drupalLogin($user);
|
||||||
|
// Create a policy
|
||||||
|
$policy_name = $this->randomName();
|
||||||
|
$edit = array(
|
||||||
|
'name' => $policy_name,
|
||||||
|
'constraint_history' => t('2'),
|
||||||
|
'roles[2]' => '2',
|
||||||
|
);
|
||||||
|
$this->drupalPost('admin/settings/password_policy/add', $edit, t('Create'));
|
||||||
|
$this->assertText('Policy ' . $policy_name . ' has been created.', 'Policy ' . $policy_name . ' has been created');
|
||||||
|
// Enable newly created policy
|
||||||
|
$pid = db_result(db_query('SELECT pid FROM {password_policy} WHERE name="%s"', $policy_name));
|
||||||
|
$constraints = unserialize(db_result(db_query('SELECT policy FROM {password_policy} WHERE pid=%d', $pid)));
|
||||||
|
$this->assertTrue($constraints['history'] == 2, t('Verified history constraint set.'));
|
||||||
|
$edit = array(
|
||||||
|
"enabled[$pid]" => $pid,
|
||||||
|
);
|
||||||
|
$this->drupalPost('admin/settings/password_policy/list', $edit, t('Save changes'));
|
||||||
|
$this->assertText(t('The changes have been saved.'), t('Form submitted successfully.'));
|
||||||
|
$enabled = db_result(db_query('SELECT enabled FROM {password_policy} WHERE pid=%d', $pid));
|
||||||
|
$this->assertTrue($enabled == 1, t('Policy enabled.'));
|
||||||
|
|
||||||
|
// Change password
|
||||||
|
$pass1 = "aaaaaa";
|
||||||
|
$edit = array(
|
||||||
|
'pass[pass1]' => $pass1,
|
||||||
|
'pass[pass2]' => $pass1,
|
||||||
|
);
|
||||||
|
$this->drupalPost("user/$user->uid/edit", $edit, t('Save'));
|
||||||
|
$this->assertText(t('The changes have been saved.'), t("1st password change: $pass1"));
|
||||||
|
// Change password second time
|
||||||
|
$pass2 = "bbbbbb";
|
||||||
|
$edit = array(
|
||||||
|
'pass[pass1]' => $pass1,
|
||||||
|
'pass[pass2]' => $pass1,
|
||||||
|
);
|
||||||
|
$this->drupalPost("user/$user->uid/edit", $edit, t('Save'));
|
||||||
|
$this->assertText(t('Your password has not met the following requirement(s):'), t("2nd password change should fail: $pass1"));
|
||||||
|
// Try changing password with the first one
|
||||||
|
$edit = array(
|
||||||
|
'pass[pass1]' => $pass2,
|
||||||
|
'pass[pass2]' => $pass2,
|
||||||
|
);
|
||||||
|
$this->drupalPost("user/$user->uid/edit", $edit, t('Save'));
|
||||||
|
$this->assertText(t('The changes have been saved.'), t("3rd password change should pass: $pass2"));
|
||||||
|
// Change password again
|
||||||
|
$pass3 = "cccccc";
|
||||||
|
$edit = array(
|
||||||
|
'pass[pass1]' => $pass3,
|
||||||
|
'pass[pass2]' => $pass3,
|
||||||
|
);
|
||||||
|
$this->drupalPost("user/$user->uid/edit", $edit, t('Save'));
|
||||||
|
$this->assertText(t('The changes have been saved.'), t("4th password change should pass: $pass3"));
|
||||||
|
|
||||||
|
// Delete test policy
|
||||||
|
$this->drupalPost('admin/settings/password_policy/delete/' . $pid, array(), t('Delete'));
|
||||||
|
$this->assertText('Password policy ' . $policy_name . ' was deleted.', 'Default password policy ' . $policy_name . 'was deleted');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testDigitPlacementConstraint() {
|
||||||
|
module_load_include('inc', 'password_policy', 'constraints/constraint_digit_placement');
|
||||||
|
$constraint = 0;
|
||||||
|
$uid = 0;
|
||||||
|
$pass = 'ILove2Password';
|
||||||
|
$result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'One numeric character in the digit placement constraint with param 0');
|
||||||
|
$pass = 'ILovePassword2';
|
||||||
|
$result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'One numeric character in the digit placement constraint with param 0');
|
||||||
|
$constraint = 1;
|
||||||
|
$pass = 'ILove2Password';
|
||||||
|
$result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'One numeric character in the digit placement constraint with param 1');
|
||||||
|
$pass = 'ILovePassword2';
|
||||||
|
$result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'One numeric character in the digit placement constraint with param 1');
|
||||||
|
$constraint = 2;
|
||||||
|
$pass = 'ILove2Password';
|
||||||
|
$result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'One numeric character in the digit placement constraint with param 2');
|
||||||
|
$pass = 'ILovePassword2';
|
||||||
|
$result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertFalse($result, 'One numeric character in the digit placement constraint with param 2');
|
||||||
|
$pass = '1LovePassword';
|
||||||
|
$result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertFalse($result, 'One numeric character in the digit placement constraint with param 2');
|
||||||
|
$pass = '1LovePassword2';
|
||||||
|
$result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'One numeric character in the digit placement constraint with param 2');
|
||||||
|
$pass = 'ILove2Password3';
|
||||||
|
$result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
|
||||||
|
$this->assertTrue($result, 'One numeric character in the digit placement constraint with param 2');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PasswordPolicyForcePasswordChangeTestCase extends DrupalWebTestCase {
|
||||||
|
protected $admin_user;
|
||||||
|
|
||||||
|
public static function getInfo() {
|
||||||
|
return array(
|
||||||
|
'name' => 'Force password change tests',
|
||||||
|
'description' => 'Tests forced password reset for single user, role and all new users.',
|
||||||
|
'group' => 'Password Policy',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
if (defined('USER_LOAD_PHPASS_PATCHED')) {
|
||||||
|
parent::setUp('password_policy', 'phpass');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
parent::setUp('password_policy');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// test permissions
|
||||||
|
public function testPerms() {
|
||||||
|
// no perms
|
||||||
|
$user = $this->drupalCreateUser();
|
||||||
|
$this->drupalLogin($user);
|
||||||
|
$this->drupalGet('admin/settings/password_policy/password_change');
|
||||||
|
$this->assertResponse('403', t('Acces should be denied.'));
|
||||||
|
$this->drupalLogout();
|
||||||
|
|
||||||
|
// with perms
|
||||||
|
$user = $this->drupalCreateUser(array('force password change'));
|
||||||
|
$this->drupalLogin($user);
|
||||||
|
$this->drupalGet('admin/settings/password_policy/password_change');
|
||||||
|
$this->assertResponse('200', t('Access should be granted.'));
|
||||||
|
$this->drupalLogout();
|
||||||
|
}
|
||||||
|
|
||||||
|
// test form elements
|
||||||
|
public function testForms() {
|
||||||
|
// test admin form
|
||||||
|
$user = $this->drupalCreateUser(array('force password change', 'administer users'));
|
||||||
|
$this->drupalLogin($user);
|
||||||
|
$this->drupalGet('admin/settings/password_policy/password_change');
|
||||||
|
$this->assertFieldByName('password_policy_new_login_change', '', t('Found first time login change checkbox.'));
|
||||||
|
$this->assertFieldByName('password_policy_force_change_roles[2]', '', t('Found roles checkboxes.'));
|
||||||
|
$this->assertFieldById('edit-submit', '', t('Found submit button.'));
|
||||||
|
|
||||||
|
// test user edit form with perms
|
||||||
|
$this->drupalGet("user/$user->uid/edit");
|
||||||
|
$this->assertFieldByName('force_password_change', '', 'Force password change checkbox is visible to admin.');
|
||||||
|
$this->drupalLogout();
|
||||||
|
|
||||||
|
// test user edit form without perms
|
||||||
|
$user = $this->drupalCreateUser();
|
||||||
|
$this->drupalLogin($user);
|
||||||
|
$this->drupalGet("user/$user->uid/edit");
|
||||||
|
$this->assertNoFieldByName('force_password_change', '', 'Force password change checkbox is hidden for normal users.');
|
||||||
|
$this->drupalLogout();
|
||||||
|
}
|
||||||
|
|
||||||
|
// test single user password change
|
||||||
|
public function testSingleUser() {
|
||||||
|
$admin = $this->drupalCreateUser(array('force password change', 'administer users'));
|
||||||
|
$user = $this->drupalCreateUser();
|
||||||
|
$this->drupalLogin($admin);
|
||||||
|
$edit = array(
|
||||||
|
'force_password_change' => TRUE,
|
||||||
|
);
|
||||||
|
$this->drupalPost("user/$user->uid/edit", $edit, t('Save'));
|
||||||
|
$this->assertRaw(t('!user will be required to change their password the next time they log in.', array('!user' => $user->name)), t('User flagged for password change.'));
|
||||||
|
$force_change = db_result(db_query('SELECT force_change FROM {password_policy_force_change} WHERE uid=%d', $user->uid));
|
||||||
|
$this->assertTrue($force_change == 1, t('Force change flag set to %d for %s.', array('%d' => $force_change, '%s' => $user->name)));
|
||||||
|
|
||||||
|
//confirm admin can edit user account without changing password
|
||||||
|
$edit = array(
|
||||||
|
'name' => $user->name,
|
||||||
|
'mail' => $user->mail,
|
||||||
|
'force_password_change' => TRUE,
|
||||||
|
);
|
||||||
|
$this->drupalPost("user/$user->uid/edit", $edit, t('Save'));
|
||||||
|
$force_change = db_result(db_query('SELECT force_change FROM {password_policy_force_change} WHERE uid=%d', $user->uid));
|
||||||
|
$this->assertTrue($force_change == 1, t('User force change flag set in database:%s.', array('%s' => $force_change)));
|
||||||
|
$this->assertNoRaw(t('An administrator has required that you change your password. You must change your password to proceed on the site.'), t('Admin can edit user account without changing password.'));
|
||||||
|
$this->drupalLogout();
|
||||||
|
|
||||||
|
// verify user is forced to change password
|
||||||
|
$this->drupalLogin($user);
|
||||||
|
$this->assertFieldByName('mail', '', t('User redirected correctly.')); // marginal
|
||||||
|
$this->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), t('User presented with error instructing them to change their password.'));
|
||||||
|
|
||||||
|
// attempt to change password
|
||||||
|
$edit = array(
|
||||||
|
'mail' => $user->mail,
|
||||||
|
'pass[pass1]' => 'random_string',
|
||||||
|
'pass[pass2]' => 'random_string',
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->drupalPost("user/$user->uid/edit", $edit, t('Save'));
|
||||||
|
$this->assertRaw(t('The changes have been saved.'), t('Password change successful.'));
|
||||||
|
|
||||||
|
// verify user not prompted to change password a 2nd time
|
||||||
|
$this->drupalGet('node');
|
||||||
|
$this->assertNoFieldByName('mail', '', t('User not forced to change password a 2nd time.'));
|
||||||
|
$this->drupalLogout();
|
||||||
|
}
|
||||||
|
|
||||||
|
// test role-based password change
|
||||||
|
public function testRoleChange() {
|
||||||
|
$admin = $this->drupalCreateUser(array('administer users', 'force password change'));
|
||||||
|
$user1 = $this->drupalCreateUser();
|
||||||
|
$user2 = $this->drupalCreateUser();
|
||||||
|
$this->drupalLogin($admin);
|
||||||
|
$edit = array(
|
||||||
|
'password_policy_force_change_roles[2]' => 2,
|
||||||
|
);
|
||||||
|
$this->drupalPost('admin/settings/password_policy/password_change', $edit, t('Submit'));
|
||||||
|
$this->assertText(t('Users in the following roles will be required to immediately change their password: authenticated user'), t('Authenticated users role selected.'));
|
||||||
|
$this->assertTrue($admin->uid != 1, t("Admin uid not 1: $admin->uid"));
|
||||||
|
$this->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), t('Admin (not uid 1) correctly forced to change password.'));
|
||||||
|
// test db flags for individual users
|
||||||
|
$entry_1 = db_result(db_query('SELECT uid FROM {password_policy_force_change} WHERE uid=%d', $user1->uid));
|
||||||
|
$this->assertTrue($entry_1 == $user1->uid, t("Entry created in password_policy_force_change for user $user1->uid."));
|
||||||
|
$flag_1 = db_result(db_query('SELECT force_change FROM {password_policy_force_change} WHERE uid=%d', $user1->uid));
|
||||||
|
$this->assertTrue($flag_1 == 1, t("User $user1->uid flagged: $flag_1."));
|
||||||
|
$this->drupalLogout();
|
||||||
|
//test individual users
|
||||||
|
$this->drupalLogin($user1);
|
||||||
|
$this->drupalGet('node');
|
||||||
|
$this->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), t('First test user forced to change password.'));
|
||||||
|
$this->drupalLogout();
|
||||||
|
|
||||||
|
//test 2nd user
|
||||||
|
$this->drupalLogin($user2);
|
||||||
|
$this->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), t('Second test user forced to change password.'));
|
||||||
|
$this->drupalLogout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//test new user change
|
||||||
|
public function testNewUserChange() {
|
||||||
|
$admin = $this->drupalCreateUser(array('administer users', 'force password change'));
|
||||||
|
$this->drupalLogin($admin);
|
||||||
|
$edit = array(
|
||||||
|
'password_policy_new_login_change' => TRUE,
|
||||||
|
);
|
||||||
|
$this->drupalPost('admin/settings/password_policy/password_change', $edit, t('Submit'));
|
||||||
|
$this->assertRaw(t('New users will be required to change their password on first-time login.'), t('New users required to change password on 1st login.'));
|
||||||
|
$this->drupalLogout();
|
||||||
|
$user = $this->drupalCreateUser();
|
||||||
|
$this->drupalLogin($user);
|
||||||
|
$this->drupalGet('node');
|
||||||
|
$this->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), t('New user forced to change password.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
//test admin forcing their own account to reset
|
||||||
|
public function testSelfChange() {
|
||||||
|
$admin = $this->drupalCreateUser(array('administer users', 'force password change'));
|
||||||
|
$this->drupalLogin($admin);
|
||||||
|
$this->assertNoRaw(t('Your password has expired. You must change your password to proceed on the site.'), t('Admin should not be prompted to change password yet.'));
|
||||||
|
$edit = array(
|
||||||
|
'force_password_change' => TRUE,
|
||||||
|
);
|
||||||
|
$this->drupalPost("user/$admin->uid/edit", $edit, t('Save'));
|
||||||
|
$this->assertRaw(t('The changes have been saved.'), t('Admin has queued account for password change.'));
|
||||||
|
$this->assertNoRaw(t('Your password has expired. You must change your password to proceed on the site.'), t('Admin not initially prompted to change password.'));
|
||||||
|
$this->drupalGet('node');
|
||||||
|
$this->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), t('Admin forced to change password once they try to leave account page.'));
|
||||||
|
$edit = array(
|
||||||
|
'mail' => $admin->mail,
|
||||||
|
'pass[pass1]' => 'fpcR@nd0m!',
|
||||||
|
'pass[pass2]' => 'fpcR@nd0m!',
|
||||||
|
);
|
||||||
|
$this->drupalPost("user/$admin->uid/edit", $edit, t('Save'));
|
||||||
|
$this->assertRaw(t('The changes have been saved.'), t('Admin changed password.'));
|
||||||
|
$this->drupalGet('node');
|
||||||
|
$this->assertNoRaw(t('An administrator has required that you change your password. You must change your password to proceed on the site.'), t('Not prompted to change password a 2nd time.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test unforcing a password change.
|
||||||
|
*/
|
||||||
|
public function testUnforceChange() {
|
||||||
|
$admin = $this->drupalCreateUser(array('force password change', 'administer users'));
|
||||||
|
$user = $this->drupalCreateUser();
|
||||||
|
$this->drupalLogin($admin);
|
||||||
|
// Force a password change.
|
||||||
|
$edit = array(
|
||||||
|
'force_password_change' => TRUE,
|
||||||
|
);
|
||||||
|
$this->drupalPost("user/$user->uid/edit", $edit, t('Save'));
|
||||||
|
$this->assertRaw(t('!user will be required to change their password the next time they log in.', array('!user' => $user->name)), t('User flagged for password change.'));
|
||||||
|
// Unforce the password change.
|
||||||
|
$edit = array(
|
||||||
|
'force_password_change' => FALSE,
|
||||||
|
);
|
||||||
|
$this->drupalPost("user/$user->uid/edit", $edit, t('Save'));
|
||||||
|
$force_change = db_result(db_query('SELECT force_change FROM {password_policy_force_change} WHERE uid=%d', $user->uid));
|
||||||
|
$this->assertTrue($force_change == 0, t('Force change flag set to %d for %s.', array('%d' => $force_change, '%s' => $user->name)));
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue