-
30 Dec 2011 4:35 AM #1
Ext.ux.form.PasswordMeter
Ext.ux.form.PasswordMeter
Hi I've adapted the code from the old 1.x version of PasswordMeter for Ext 4. It is based on the code posted by yyjia on his blog. I've adapted his code to use the fieldSubTpl instead of adding elements after render time. Also I align the meter to the inputfield (I prefer it that way
)
password-strength.png
And for the CSS:Code:Ext.define('Ext.ux.form.PasswordMeter', { extend : 'Ext.form.field.Text', alias : 'widget.ux.passwordmeter', inputType : 'password', reset : function() { this.callParent(); this.updateMeter(this); }, fieldSubTpl : [ '<div><input id="{id}" type="{type}" ', '<tpl if="name">name="{name}" </tpl>', '<tpl if="size">size="{size}" </tpl>', '<tpl if="tabIdx">tabIndex="{tabIdx}" </tpl>', 'class="{fieldCls} {typeCls}" autocomplete="off" /></div>', '<div class="strengthmeter">', '<div class="scorebar"> </div>', '</div>', { compiled : true, disableFormats : true } ], // private onChange : function(newValue, oldValue) { this.updateMeter(newValue); }, /** * Sets the width of the meter, based on the score * * @param {Object} * e Private function */ updateMeter : function(val) { var me = this, maxWidth, score, scoreWidth, objMeter = me.el.down('.strengthmeter'), scoreBar = me.el.down('.scorebar'); maxWidth = objMeter.getWidth(); score = me.calcStrength(val); scoreWidth = maxWidth - (maxWidth / 100) * score; scoreBar.setWidth(scoreWidth, true); }, /** * Calculates the strength of a password * * @param {Object} * p The password that needs to be calculated * @return {int} intScore The strength score of the password */ calcStrength : function(p) { var intScore = 0; // PASSWORD LENGTH intScore += p.length; if (p.length > 0 && p.length <= 4) { // length 4 or // less intScore += p.length; } else if (p.length >= 5 && p.length <= 7) { // length between 5 and 7 intScore += 6; } else if (p.length >= 8 && p.length <= 15) { // length between 8 and 15 intScore += 12; } else if (p.length >= 16) { // length 16 or more intScore += 18; } // LETTERS (Not exactly implemented as dictacted above // because of my limited understanding of Regex) if (p.match(/[a-z]/)) { // [verified] at least one lower case letter intScore += 1; } if (p.match(/[A-Z]/)) { // [verified] at least one upper // case letter intScore += 5; } // NUMBERS if (p.match(/\d/)) { // [verified] at least one // number intScore += 5; } if (p.match(/(?:.*?\d){3}/)) { // [verified] at least three numbers intScore += 5; } // SPECIAL CHAR if (p.match(/[\!,@,#,$,%,\^,&,\*,\?,_,~]/)) { // [verified] at least one special character intScore += 5; } // [verified] at least two special characters if (p.match(/(?:.*?[\!,@,#,$,%,\^,&,\*,\?,_,~]){2}/)) { intScore += 5; } // COMBOS if (p.match(/(?=.*[a-z])(?=.*[A-Z])/)) { // [verified] both upper and lower case intScore += 2; } if (p.match(/(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/)) { // [verified] both letters and numbers intScore += 2; } // [verified] letters, numbers, and special characters if (p.match(/(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\!,@,#,$,%,\^,&,\*,\?,_,~])/)) { intScore += 2; } var nRound = Math.round(intScore * 2); if (nRound > 100) { nRound = 100; } return nRound; } });
You can find the background image here.Code:.strengthmeter { background-image: url(../images/meter.gif); background-size: 100%; width : 100%; float: right; } .scorebar { background-color : white; float: right; line-height : 6px; width : 100%; }
-
30 Dec 2011 8:13 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,117
- Vote Rating
- 453
You should post a couple screenshots so we can look at it without putting the code in and testing it.
Also, may want to check out http://market.sencha.com
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
16 Feb 2012 5:11 AM #3
i have made some small changes to prevent an error if the field without any value is reset():
Code:reset : function() { this.callParent(); this.updateMeter(); },
Code:updateMeter : function(val) { var me = this, maxWidth, score, scoreWidth, objMeter = me.el.down('.strengthmeter'), scoreBar = me.el.down('.scorebar'); if (val){ maxWidth = objMeter.getWidth(); score = me.calcStrength(val); scoreWidth = maxWidth - (maxWidth / 100) * score; scoreBar.setWidth(scoreWidth, true); } else { scoreBar.setWidth(0, true); } },
-
24 Feb 2012 7:18 AM #4
Example please
Example please
Do you have some implementation examle?
www.codelighter.com
There are 10 types of people in this world, those who understand binary and those who dont
-
1 Mar 2012 3:06 PM #5
Demo + Background image replaced through CSS gradient (+ some other enhancements):
http://jsfiddle.net/SunboX/f8xUz/11/
greetings Sunny
-
6 Sep 2012 1:52 AM #6
Hi,
width of password field does not changing
PHP Code:items: [{
xtype: 'ux.passwordmeterfield',
labelAlign: 'left',
fieldLabel: 'Password',
name: 'foo',
anchor: '100%',
margin: '0 0 20 0',
width: 200 // <---
}]
-
18 Oct 2012 7:47 AM #7
Yes it's true. I try find a problem and found block after this field it took a space from right

-
29 Oct 2012 5:48 PM #8
Fixed. Add the following line inside the HTML tag input, under the config property fieldSubTpl (on @SunboX code it would be on line 14).
Code:'<tpl if="fieldStyle"> style="{fieldStyle}"</tpl>',
-
30 Oct 2012 10:29 AM #9
I tried to update the code on JSFiddle with the fix, but it created a new link:
http://jsfiddle.net/rgralhoz/f8xUz/75/


Reply With Quote

