{"id":496,"date":"2012-03-22T14:23:07","date_gmt":"2012-03-22T19:23:07","guid":{"rendered":"http:\/\/xlinesoft.com\/blog\/?p=496"},"modified":"2022-10-12T06:46:14","modified_gmt":"2022-10-12T11:46:14","slug":"how-to-add-password-strength-meter-to-your-registration-page","status":"publish","type":"post","link":"https:\/\/xlinesoft.com\/blog\/2012\/03\/22\/how-to-add-password-strength-meter-to-your-registration-page\/","title":{"rendered":"How to add Password Strength Meter to your registration page"},"content":{"rendered":"<p>In this article, we&#8217;ll show you how to add a password strength meter to ASPRunnerPro\/PHPRunner registration page. This meter is a handy way to show users how weak or strong their password is. This code requires ASPRunnerPro 7.x or PHPRunner 6.x in order to work properly. <a href=\"http:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/password_strength_meter.zip\">Download article code<\/a>.<\/p>\n<p>For this purpose we are going to use jQuery password strength plugin developed by <a href=\"http:\/\/www.intelligent-web.co.uk\/tutorials\/passwordvalidation\/\">Olivier Oechsle<\/a>. Make sure to check plugin page if you are interested in internal workings or fancy to improve it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-497\" title=\"password_strength_meter\" src=\"http:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2012\/03\/password_strength_meter.png\" alt=\"Password strength meter\" width=\"572\" height=\"228\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2012\/03\/password_strength_meter.png 572w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2012\/03\/password_strength_meter-300x119.png 300w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2012\/03\/password_strength_meter-150x59.png 150w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2012\/03\/password_strength_meter-400x159.png 400w\" sizes=\"auto, (max-width: 572px) 100vw, 572px\" \/><\/p>\n<p><!--more--><\/p>\n<h3>Step 1. Add CSS to Register page<\/h3>\n<p>The following CSS code needs to be added in Visual Editor to Register page right before &lt;\/HEAD&gt; tag. Make sure you switch to HTML mode before pasting the code.<\/p>\n<pre lang=\"css\"><!--\r\ninput[type='password'] {\r\n  width: 180px; \r\n}\r\n\r\n.passwordStrengthBar { \r\n    background: white; \r\n    border: 1px solid #777777; \r\n    margin: 1px; \r\n    width: 180px; \r\n} \r\n\r\n.passwordStrengthBar div { \r\n    height: 5px; \r\n    width: 0; \r\n} \r\n\r\n.passwordStrengthBar div.strong { \r\n    background-color: #32cd32; \r\n} \r\n\r\n.passwordStrengthBar div.medium { \r\n    background-color: yellow; \r\n} \r\n\r\n.passwordStrengthBar div.weak { \r\n    background-color: orange; \r\n} \r\n\r\n.passwordStrengthBar div.useless { \r\n    background-color: red; \r\n} \r\n--><\/pre>\n<h3>Step 2. Add Javascript code to Register page: Javascript OnLoad event<\/h3>\n<pre lang=\"javascript\">\/* Intelligent Web NameSpace *\/\r\nvar IW = IW || {}; \r\n\r\n\/**\r\n * Password validator logic\r\n *\/\r\n(function(IW) { \r\n\r\n    var secondsInADay = 86400; \r\n\r\n    function PasswordValidator() {\r\n    } \r\n\r\n    \/**\r\n     * How long a password can be expected to last\r\n     *\/\r\n    PasswordValidator.prototype.passwordLifeTimeInDays = 365; \r\n\r\n    \/**\r\n     * An estimate of how many attempts could be made per second to guess a password\r\n     *\/\r\n    PasswordValidator.prototype.passwordAttemptsPerSecond = 500; \r\n\r\n    \/**\r\n     * An array of regular expressions to match against the password. Each is associated\r\n     * with the number of unique characters that each expression can match.\r\n     * @param password\r\n     *\/\r\n    PasswordValidator.prototype.expressions = [\r\n        {\r\n            regex : \/[A-Z]+\/,\r\n            uniqueChars : 26\r\n        },\r\n        {\r\n            regex : \/[a-z]+\/,\r\n            uniqueChars : 26\r\n        },\r\n        {\r\n            regex : \/[0-9]+\/,\r\n            uniqueChars : 10\r\n        },\r\n        {\r\n            regex : \/[!\\?.;,\\\\@$\u00a3#*()%~&lt;&gt;{}\\[\\]]+\/,\r\n            uniqueChars : 17\r\n        }\r\n    ]; \r\n\r\n    \/**\r\n     * Checks the supplied password\r\n     * @param {String} password\r\n     * @return The predicted lifetime of the password, as a percentage of the defined password lifetime.\r\n     *\/\r\n    PasswordValidator.prototype.checkPassword = function(password) { \r\n\r\n        var\r\n                expressions = this.expressions,\r\n                i,\r\n                l = expressions.length,\r\n                expression,\r\n                possibilitiesPerLetterInPassword = 0; \r\n\r\n        for (i = 0; i &lt; l; i++) { \r\n\r\n            expression = expressions[i]; \r\n\r\n            if (expression.regex.exec(password)) {\r\n                possibilitiesPerLetterInPassword += expression.uniqueChars;\r\n            } \r\n\r\n        } \r\n\r\n   var\r\n      totalCombinations = Math.pow(possibilitiesPerLetterInPassword, password.length),\r\n   \/\/ how long, on average, it would take to crack this (@ 200 attempts per second)\r\n       crackTime = ((totalCombinations \/ this.passwordAttemptsPerSecond) \/ 2) \/ secondsInADay,\r\n   \/\/ how close is the time to the projected time?\r\n       percentage = crackTime \/ this.passwordLifeTimeInDays; \r\n\r\n        return Math.min(Math.max(password.length * 5, percentage * 100), 100); \r\n\r\n    }; \r\n\r\n    IW.PasswordValidator = new PasswordValidator(); \r\n\r\n})(IW); \r\n\r\n\/**\r\n * jQuery plugin which allows you to add password validation to any\r\n * form element.\r\n *\/\r\n(function(IW, jQuery) { \r\n\r\n    function updatePassword() { \r\n\r\n        var\r\n                percentage = IW.PasswordValidator.checkPassword(this.val()),\r\n                progressBar = this.parent().find(\".passwordStrengthBar div\"); \r\n\r\n        progressBar\r\n                .removeClass(\"strong medium weak useless\")\r\n                .stop()\r\n                .animate({\"width\": percentage + \"%\"}); \r\n\r\n        if (percentage &gt; 90) {\r\n            progressBar.addClass(\"strong\");\r\n        } else if (percentage &gt; 50) {\r\n            progressBar.addClass(\"medium\")\r\n        } else if (percentage &gt; 10) {\r\n            progressBar.addClass(\"weak\");\r\n        } else {\r\n            progressBar.addClass(\"useless\");\r\n        }\r\n    } \r\n\r\n    jQuery.fn.passwordValidate = function() { \r\n\r\n        this\r\n                .bind('keyup', jQuery.proxy(updatePassword, this))\r\n                .after(\"\r\n<div class=\"passwordStrengthBar\"><\/div>\r\n\"); \r\n\r\n        updatePassword.apply(this); \r\n\r\n        return this; \/\/ for chaining \r\n\r\n    } \r\n\r\n})(IW, jQuery); \r\n\r\n$(\"span[class='runner-nowrap']\").each(function() {\r\n   var $this = $(this);\r\n   var t = $this.html();\r\n   $this.html(t.replace('\u00a0',''));\r\n});\r\n$(\"input[type='password']\").next().remove();\r\njQuery(\"input[id='value_Password_1']\").passwordValidate();<\/pre>\n<p>This code assumes that your password field name is <strong>Password<\/strong>. Your password field name is different make sure to amend the last line of Javascript code. I.e. if password field name is <strong>pass<\/strong> here is how your code should look:<\/p>\n<pre lang=\"javascript\">jQuery(\"input[id='value_pass_1']\").passwordValidate();<\/pre>\n<p>Additional considerations:<\/p>\n<ul>\n<li>You may want to add the same code to Change password page.<\/li>\n<li>If you decide to modify the plugin consider adding wording &#8216;weak&#8217;, &#8216;strong&#8217; etc to the meter. You can also make sure password is not equals to username<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we&#8217;ll show you how to add a password strength meter to ASPRunnerPro\/PHPRunner registration page. This meter is a handy way to show users how weak or strong their password is. This code requires ASPRunnerPro 7.x or PHPRunner 6.x in order to work properly. Download article code. For this purpose we are going to use jQuery password strength plugin developed by Olivier Oechsle. Make sure to check plugin page if you are interested in internal workings or fancy to improve it.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,1,4,3],"tags":[],"class_list":["post-496","post","type-post","status-publish","format-standard","hentry","category-news","category-php-category","category-php-code-generator","category-php-form-generator"],"_links":{"self":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/comments?post=496"}],"version-history":[{"count":14,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/496\/revisions"}],"predecessor-version":[{"id":2815,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/496\/revisions\/2815"}],"wp:attachment":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/media?parent=496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/categories?post=496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/tags?post=496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}