From 3d9759958558752d0c115774d2b0bc34fac7e31b Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Fri, 28 Sep 2018 12:47:17 +0200 Subject: [PATCH] Remove dependency on eval() - fixes #19 Signed-off-by: Morris Jobke --- README.md | 6 ++++++ bower.json | 2 +- jquery.strengthify.js | 14 ++++++-------- jquery.strengthify.min.js | 2 +- strengthify.css | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 43fc71a..d00f920 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,12 @@ Versions --------
+
0.5.4
+
+
    +
  • do not use `eval()` anymore (#19)
  • +
+
0.5.3
    diff --git a/bower.json b/bower.json index 5f1755e..9ebfa4e 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "strengthify", - "version": "0.5.3", + "version": "0.5.4", "homepage": "https://github.com/MorrisJobke/strengthify", "authors": [ "Eve Ragins "):"";break;case 2:i="warning",o=a.feedback?a.feedback.suggestions.join("
    "):"",r="password-medium";break;case 3:r="password-good",i="info",o="Getting better.";break;case 4:r="password-good",i="success",o="Looks good."}l&&(l.removeAttr("class"),l.addClass("bg-"+i),""===t&&(o=""),l.html(o)),d&&(d.attr("class",r+" strengthify-container").css("width",25*(0===a.score?1:a.score)+"%"),""===t&&d.css("width",0)),options.drawTitles&&(options.tilesOptions.tooltip&&(n.attr("title",options.titles[a.score]).tooltip({placement:"bottom",trigger:"manual"}).tooltip("fixTitle").tooltip("show"),0===s&&n.tooltip("hide")),options.tilesOptions.element&&n.find(".strengthify-tiles").text(options.titles[a.score]))}function init(){var $elem=$(this),elemId=$elem.attr("id"),drawSelf=drawStrengthify.bind(this),$addAfter=options.$addAfter;$addAfter||($addAfter=$elem),$addAfter.after('
    '),options.drawBars&&getWrapperFor(elemId).append('
    ').append('
    ').append('
    ').append('
    ').append('
    '),options.drawMessage&&getWrapperFor(elemId).append("
    "),options.drawTitles&&options.tilesOptions&&getWrapperFor(elemId).append('
    '),$elem.parent().on("scroll",drawSelf),$.ajax({cache:!0,url:options.zxcvbn}).done(function(content){eval(content),$elem.bind("keyup input change",drawSelf)})}options.drawTitles||options.drawMessage||options.drawBars||console.warn("expect at least one of 'drawTitles', 'drawMessage', or 'drawBars' to be true"),init.call(this)})}}(jQuery); \ No newline at end of file +(function($){$.fn.strengthify=function(paramOptions){"use strict";var defaults={zxcvbn:'zxcvbn/zxcvbn.js',titles:['Weakest','Weak','So-so','Good','Perfect'],tilesOptions:{tooltip:true,element:false},drawTitles:false,drawMessage:false,drawBars:true,$addAfter:null};return this.each(function(){var options=$.extend(defaults,paramOptions);if(!options.drawTitles&&!options.drawMessage&&!options.drawBars){console.warn("expect at least one of 'drawTitles', 'drawMessage', or 'drawBars' to be true")}function getWrapperFor(id){return $('div[data-strengthifyFor="'+id+'"]')};function drawStrengthify(){var password=$(this).val(),elemId=$(this).attr('id'),opacity=(password==='')?0:1,result=zxcvbn(password),css='',bsLevel='',message='',$wrapper=getWrapperFor(elemId),$container=$wrapper.find('.strengthify-container'),$message=$wrapper.find('[data-strengthifyMessage]');$wrapper.children().css('opacity',opacity).css('-ms-filter','"progid:DXImageTransform.Microsoft.Alpha(Opacity='+opacity*100+')"');if(options.onResult){options.onResult(result)}switch(result.score){case 0:case 1:css='password-bad';bsLevel='danger';message=result.feedback?result.feedback.suggestions.join('
    '):"";break;case 2:bsLevel='warning';message=result.feedback?result.feedback.suggestions.join('
    '):"";css='password-medium';break;case 3:css='password-good';bsLevel='info';message="Getting better.";break;case 4:css='password-good';bsLevel='success';message="Looks good.";break}if($message){$message.removeAttr('class');$message.addClass('bg-'+bsLevel);if(password===''){message=''}$message.html(message)}if($container){$container.attr('class',css+' strengthify-container').css('width',((result.score===0?1:result.score)*25)+'%');if(password===''){$container.css('width',0)}}if(options.drawTitles){if(options.tilesOptions.tooltip){$wrapper.attr('title',options.titles[result.score]).tooltip({placement:'bottom',trigger:'manual'}).tooltip('fixTitle').tooltip('show');if(opacity===0){$wrapper.tooltip('hide')}}if(options.tilesOptions.element){$wrapper.find(".strengthify-tiles").text(options.titles[result.score])}}};function init(){var $elem=$(this),elemId=$elem.attr('id');var drawSelf=drawStrengthify.bind(this);var $addAfter=options.$addAfter;if(!$addAfter){$addAfter=$elem}$addAfter.after('
    ');if(options.drawBars){getWrapperFor(elemId).append('
    ').append('
    ').append('
    ').append('
    ').append('
    ')}if(options.drawMessage){getWrapperFor(elemId).append('
    ')}if(options.drawTitles&&options.tilesOptions){getWrapperFor(elemId).append('
    ')}$elem.parent().on('scroll',drawSelf);var script=document.createElement("script");script.src=options.zxcvbn;document.head.appendChild(script);$elem.bind('keyup input change',drawSelf)};init.call(this);})}}(jQuery)); \ No newline at end of file diff --git a/strengthify.css b/strengthify.css index a3710e5..f94e9cc 100644 --- a/strengthify.css +++ b/strengthify.css @@ -1,7 +1,7 @@ /** * Strengthify - show the weakness of a password (uses zxcvbn for this) * https://github.com/MorrisJobke/strengthify - * Version: 0.5.3 + * Version: 0.5.4 * License: The MIT License (MIT) * Copyright (c) 2013-2016 Morris Jobke */