密碼強度檢測的jQuery插件:Entropizer

jopen 9年前發布 | 15K 次閱讀 jQuery插件 Entropizer

jQuery Entropizer 是一個簡單,輕量級的jQuery插件,使用Entropizer引擎來計算密碼強度。它易于使用并提供多個鉤子來定制UI。

// Create an Entropizer meter using custom options
$('#meter').entropizer({

// The input field to watch: any selector, DOM element or jQuery instance
// Default: 'input[type=password]:first'
target: '#pwd',

// The event(s) upon which to update the meter UI
// Default: 'keydown keyup'
on: 'keydown',

// Used to calculate the percentage of the bar to fill (see map function below)
// Default: 100
maximum: 80,

// An array of ranges to use when classifying password strength. Used internally by default map
// function and can be used publicly via $.entropizer.classify(value, buckets). Properties
// 'min' and 'max' are used to calculate which bucket to use - upon finding a match, an object
// containing all the other properties is returned, e.g. below, a value of 42 returns
// { message: ':)' }
// Default: 4 ranges with strength and color properties (see source for values)
buckets: [
    { max: 40, message: ':(' },
    { min: 40, max: 60, message: ':)' },
    { min: 60, message: ':D' }
],

// Either an Entropizer engine options object or an Entropizer instance
// Default: a new Entropizer instance with default settings
engine: {
    classes: ['lowercase', 'uppercase', 'numeric']
},

// A callback controlling UI creation - takes a jQuery instance representing the container
// and returns an object containing UI components for access in update and destroy
// Default: creates a track element (the bar background), a bar element and a text element
create: function(container) {
    var bar = $('<div>').appendTo(container);
    return { foo: bar };
},

// A callback controlling UI cleanup - takes the UI object created by create
// Default: removes the track, bar and text elements
destroy: function(ui) {
    ui.foo.remove();
},

// A callback that maps the raw entropy value to an object passed to update. First argument is
// the number of bits of entropy, second argument is an object containing all properties on
// the options object apart from target, on, engine and the callbacks (i.e. by default, just
// maximum and buckets)
// Default: uses maximum and buckets above to return an object with entropy, percent, strength
// and color properties
map: function(entropy, mapOptions) {
    return $.extend({ entropy: entropy }, $.entropizer.classify(entropy, mapOptions.buckets));
},

// A callback controlling UI updates - takes the data returned by map and the ui object
// Default: updates the width and background color of the bar, and displays the number of bits
update: function(data, ui) {
    ui.foo.text(data.entropy.toFixed(0) + ' ' + data.message);
}

});</pre>



項目主頁:http://www.baiduhome.net/lib/view/home/1433230124447



 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!