Internet users are famous for using the simplest possible passwords and using the same password on many sites. In some cases that is unimportant but if you have any sensitive or valuable material on your site you may want to ensure that user passwords are at least reasonably secure. This FAQ shows you how to add a strength checker to a password input.
This FAQ uses MooTools and is written for CFv4 - see here for a CFv5 version.
There are several Password Strength checkers available, I chose to use Dimitar Christoff's StrongPass which is written for MooTools 1.4 (used on Joomla! 2.5+). StrongPass provides neat cisual feedback, allows customised rules and includes a 'block' list for very common passwords. There is more information and links to demonstrations on the StrongPass GitHub page.
To use StrongPass with ChronoForms you need to click the ZIP icon on the GitHub download and unzip the package. We will only need the StrongPass.js in the Source folder.
On the website where I am using StrongPass I added a new 'extras' folder: /components/com_chronoforms/extras and uploaded StrongPass.js to it.
In the form I added a Load JS and a Load CSS action to the form On Load action; and in the preview window I added an Password Box input and gave it the name and ID password_1
You can use a different folder for the StrongPass.js file, or a different name and ID for the Password Box provided that you adjust the following code to match.
In the Load JS action add the following code making sure that the highlighted code matches the settings on your site:
<?php // if you are using this code in Joomla! 3 please uncomment the next line // JHtml::_('behavior.framework', true); $doc =& JFactory::getDocument(); $doc->addScript(JURI::root().'components/com_chronoforms/extras/StrongPass.js'); ?> window.addEvent('domready', function() { new StrongPass("password_1"); });
Note, there are several console.log lines here that are commented out, each of these is an event triggered by StrongPass that you could use to customise StongPass on your site by showing a message, changing CSS styles, etc. In this FAQ we only use the default settings.
div.pass-container { height: 30px; padding-left: 150px; } div.pass-bar { height: 11px; margin-top: 2px; } div.pass-hint { font-family: arial; font-size: 11px; }
Setting options
new StrongPass("password_1", {
minChar: 8 // too short while less than this
});
The options include various styling and placement settings; the text used for messages (you can change the language using these); and setting for password strength checking and banning. See the StrongPass.js file for the full set.
Here's an example with the language settings:
new StrongPass("password_1", {
label: 'Try for five stars: ',
verdicts: [
Setting events
More advanced than this tutorial but StrongPass also has four events that you can use to fire actions. They are onReady, onPass, onFail, and onBanned. You could for example have the input box flash red when a banned password is entered:
new StrongPass("password_1", {
onBanned: function(word) {
$('password_1').highlight('#f00');
Banned Passwords