1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| 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">&nbsp;</div>', '</div>', { compiled : true, disableFormats : true } ],
onChange : function(newValue, oldValue) { this.updateMeter(newValue); },
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); },
calcStrength : function(p) { var intScore = 0;
intScore = p.length;
if (p.length > 0 && p.length <= 4) { intScore = p.length; } else if (p.length >= 5 && p.length <= 7) { intScore = 6; } else if (p.length >= 8 && p.length <= 15) { intScore = 12; } else if (p.length >= 16) { intScore = 18; }
if (p.match(/[a-z]/)) { intScore = 1; } if (p.match(/[A-Z]/)) { intScore = 5; } if (p.match(/\d/)) { intScore = 5; } if (p.match(/(?:.*?\d){3}/)) { intScore = 5; } if (p.match(/[\!,@,#,$,%,\^,&,\*,\?,_,~]/)) { intScore = 5; } if (p.match(/(?:.*?[\!,@,#,$,%,\^,&,\*,\?,_,~]){2}/)) { intScore = 5; }
if (p.match(/(?=.*[a-z])(?=.*[A-Z])/)) { intScore = 2; } if (p.match(/(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/)) { intScore = 2; } if (p.match(/(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\!,@,#,$,%,\^,&,\*,\?,_,~])/)) { intScore = 2; }
var nRound = Math.round(intScore * 2);
if (nRound > 100) { nRound = 100; } return nRound; } });
|