From 69a2e76c3ce39276b21acd62150af24cdacebc96 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sun, 23 Sep 2012 14:07:50 -0500 Subject: [PATCH] entropy check code in web2py.js, thanks Niphlod --- VERSION | 2 +- applications/admin/static/js/web2py.js | 56 +++++++++--- applications/examples/static/js/web2py.js | 56 +++++++++--- applications/welcome/static/js/web2py.js | 52 ++++++++--- applications/welcome/views/default/user.html | 91 +------------------- gluon/sqlhtml.py | 20 +++-- 6 files changed, 142 insertions(+), 135 deletions(-) diff --git a/VERSION b/VERSION index a6b55e7f..c8c7db93 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.0.9 (2012-09-22 11:19:10) stable +Version 2.0.9 (2012-09-23 14:07:45) stable diff --git a/applications/admin/static/js/web2py.js b/applications/admin/static/js/web2py.js index 9a2e208c..e323398a 100644 --- a/applications/admin/static/js/web2py.js +++ b/applications/admin/static/js/web2py.js @@ -39,7 +39,7 @@ function web2py_ajax_init(target) { function web2py_event_handlers() { var doc = jQuery(document) - doc.on('click', '.flash', function(e){jQuery(this).fadeOut('slow'); e.preventDefault();}); + doc.on('click', '.flash', function(e){var t=jQuery(this); if(t.css('top')=='0px') t.slideUp('slow'); else t.fadeOut(); e.preventDefault();}); doc.on('keyup', 'input.integer', function(){this.value=this.value.reverse().replace(/[^0-9\-]|\-(?=.)/g,'').reverse();}); doc.on('keyup', 'input.double, input.decimal', function(){this.value=this.value.reverse().replace(/[^0-9\-\.,]|[\-](?=.)|[\.,](?=[0-9]*[\.,])/g,'').reverse();}); var confirm_message = (typeof w2p_ajax_confirm_message != 'undefined') ? w2p_ajax_confirm_message : "Are you sure you want to delete this object?"; @@ -55,7 +55,7 @@ function web2py_event_handlers() { jQuery(function() { var flash = jQuery('.flash'); flash.hide(); - if(flash.html()) flash.slideDown(); + if(flash.html()) flash.append('×').slideDown(); web2py_ajax_init(document); web2py_event_handlers(); }); @@ -67,20 +67,20 @@ function web2py_trap_form(action,target) { form.submit(function(e){ jQuery('.flash').hide().html(''); web2py_ajax_page('post',action,form.serialize(),target); - e.preventDefault(); + e.preventDefault(); }); }); } function web2py_trap_link(target) { jQuery('#'+target+' a.w2p_trap').each(function(i){ - var link=jQuery(this); - link.click(function(e) { - jQuery('.flash').hide().html(''); - web2py_ajax_page('get',link.attr('href'),[],target); - e.preventDefault(); - }); - }); + var link=jQuery(this); + link.click(function(e) { + jQuery('.flash').hide().html(''); + web2py_ajax_page('get',link.attr('href'),[],target); + e.preventDefault(); + }); + }); } function web2py_ajax_page(method, action, data, target) { @@ -101,9 +101,9 @@ function web2py_ajax_page(method, action, data, target) { web2py_trap_link(target); web2py_ajax_init('#'+target); if(command) - eval(decodeURIComponent(command)); + eval(decodeURIComponent(command)); if(flash) - jQuery('.flash').html(decodeURIComponent(flash)).slideDown(); + jQuery('.flash').html(decodeURIComponent(flash)).slideDown(); } }); } @@ -151,7 +151,7 @@ function web2py_component(action, target, timeout, times){ } } else { // run once (no timeout specified) - element.reload_counter = Infinity; + element.reload_counter = Infinity; web2py_ajax_page('get', action, null, target); } }); } @@ -165,3 +165,33 @@ function web2py_comet(url,onmessage,onopen,onclose) { } else return false; // not supported } + +function web2py_calc_entropy(mystring) { + //calculate a simple entropy for a given string + var csets = new Array( + 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', + '0123456789', '!@#$\%^&*()', '~`-_=+[]{}\|;:\'",.<>?/', + '0123456789abcdefghijklmnopqrstuvwxyz'); + var score = 0, other = {}, seen = {}, lastset = null, mystringlist = mystring.split(''); + for (var i=0;i×').slideDown(); web2py_ajax_init(document); web2py_event_handlers(); }); @@ -67,20 +67,20 @@ function web2py_trap_form(action,target) { form.submit(function(e){ jQuery('.flash').hide().html(''); web2py_ajax_page('post',action,form.serialize(),target); - e.preventDefault(); + e.preventDefault(); }); }); } function web2py_trap_link(target) { jQuery('#'+target+' a.w2p_trap').each(function(i){ - var link=jQuery(this); - link.click(function(e) { - jQuery('.flash').hide().html(''); - web2py_ajax_page('get',link.attr('href'),[],target); - e.preventDefault(); - }); - }); + var link=jQuery(this); + link.click(function(e) { + jQuery('.flash').hide().html(''); + web2py_ajax_page('get',link.attr('href'),[],target); + e.preventDefault(); + }); + }); } function web2py_ajax_page(method, action, data, target) { @@ -101,9 +101,9 @@ function web2py_ajax_page(method, action, data, target) { web2py_trap_link(target); web2py_ajax_init('#'+target); if(command) - eval(decodeURIComponent(command)); + eval(decodeURIComponent(command)); if(flash) - jQuery('.flash').html(decodeURIComponent(flash)).slideDown(); + jQuery('.flash').html(decodeURIComponent(flash)).slideDown(); } }); } @@ -151,7 +151,7 @@ function web2py_component(action, target, timeout, times){ } } else { // run once (no timeout specified) - element.reload_counter = Infinity; + element.reload_counter = Infinity; web2py_ajax_page('get', action, null, target); } }); } @@ -165,3 +165,33 @@ function web2py_comet(url,onmessage,onopen,onclose) { } else return false; // not supported } + +function web2py_calc_entropy(mystring) { + //calculate a simple entropy for a given string + var csets = new Array( + 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', + '0123456789', '!@#$\%^&*()', '~`-_=+[]{}\|;:\'",.<>?/', + '0123456789abcdefghijklmnopqrstuvwxyz'); + var score = 0, other = {}, seen = {}, lastset = null, mystringlist = mystring.split(''); + for (var i=0;i?/', + '0123456789abcdefghijklmnopqrstuvwxyz'); + var score = 0, other = {}, seen = {}, lastset = null, mystringlist = mystring.split(''); + for (var i=0;i - diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index e63a909d..2fbf3c14 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -28,7 +28,7 @@ from dal import DAL, Field, Table, Row, CALLABLETYPES, smart_query, \ from storage import Storage from utils import md5_hash from validators import IS_EMPTY_OR, IS_NOT_EMPTY, IS_LIST_OF, IS_DATE, \ - IS_DATETIME, IS_INT_IN_RANGE, IS_FLOAT_IN_RANGE + IS_DATETIME, IS_INT_IN_RANGE, IS_FLOAT_IN_RANGE, IS_STRONG import datetime import urllib @@ -442,14 +442,23 @@ class PasswordWidget(FormWidget): see also: :meth:`FormWidget.widget` """ - + # detect if attached a IS_STRONG with entropy default=dict( _type='password', _value=(value and cls.DEFAULT_PASSWORD_DISPLAY) or '', ) attr = cls._attributes(field, default, **attributes) + output = CAT(INPUT(**attr)) - return INPUT(**attr) + # deal with entropy check! + requires = field.requires + if not isinstance(requires,(list,tuple)): requires = [requires] + is_strong = [r for r in requires if isinstance(r, IS_STRONG)] + if is_strong: + output.append(SCRIPT("web2py_validate_entropy(jQuery('#%s'),%s);" \ + % (attr['_id'],is_strong[0].entropy))) + # end entropy check + return output class UploadWidget(FormWidget): @@ -2713,8 +2722,3 @@ class ExporterXML(ExportClass): out.write('\n') out.write('') return str(out.getvalue()) - - - - -