-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassfun.js
More file actions
146 lines (137 loc) · 5.04 KB
/
passfun.js
File metadata and controls
146 lines (137 loc) · 5.04 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* passFun.js
*
* Author
* Igor Sawczuk <isawczuk at gmail dot com> -- agniwa.pl
*
*
* License
* MIT License (see below)
*
* ---------------------------------------------------------------
* Copyright (c) 2012 Igor Sawczuk <isawczuk at gmail dot com>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
* KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
* OR OTHER DEALINGS IN THE SOFTWARE.
* ---------------------------------------------------------------
*
* Displaying password strength should be fun and understandable for every one.
* ===========================================================================
* v0.1 - my first attempt. it uses external lib to meter your password
* and display pixelized image based on how strong is password
*
*
* FAST START
* ==========
* <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
* $(document).ready(function() {
* $('#nicepass').passFun();
* });
* <canvas id="passfun_canvas" class="tip" width="360", height="360"></canvas>
*/
(function( $ ){
var methods = {
init : function( options ) {
return this.each(function(){
$(this).bind('focus', methods.focus);
$(this).bind('keyup', methods.keyup);
$(this).bind('blur', methods.blur);
//stworz obiekt
});
},
destroy : function( ) {
return this.each(function(){
//$(window).unbind('.tooltip');
})
},
keyup : function( ) {
passwordCheck($(this).val(), function(result) {
var canvas = document.getElementById("passfun_canvas");
var context = canvas.getContext("2d");
var pixx = 45 - result.score;
var myImage = new Image();
myImage.onload = function() {
var sourceWidth = myImage.width;
var sourceHeight = myImage.height;
var destX = canvas.width / 2 - sourceWidth / 2;
var destY = canvas.height / 2 - sourceHeight / 2;
context.drawImage(myImage, destX, destY);
if(pixx > 5) {
focusImage(context, myImage, sourceWidth, sourceHeight, destX, destY,pixx);
context.fillStyle = '#f00';
context.font = 'italic bold 10px sans-serif';
context.textBaseline = 'bottom';
context.fillText('Password is ' + result.verdict + '. Improve password to see image.', 10, 10);
}
}
myImage.src = "test.jpg";
});
},
focus : function( ) {
var tipY = $(this).position().top;
var tipX = $(this).position().left+$(this).width()+10;
$('#passfun_canvas').css({ top: tipY, left: tipX });
$('#passfun_canvas').show();
},
show : function( ) {
// ...
},
hide : function( ) {
// ...
},
update : function( content ) {
// ...
}
};
$.fn.passFun = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.passFun' );
}
};
})( jQuery );
function focusImage(context, imageObj, sourceWidth, sourceHeight, destX, destY,pix){
var sourceX = destX;
var sourceY = destY;
var imageData = context.getImageData(sourceX, sourceY, sourceWidth, sourceHeight);
var data = imageData.data;
for (var y = 0; y < sourceHeight; y += pix) {
for (var x = 0; x < sourceWidth; x += pix) {
var red = data[((sourceWidth * y) + x) * 4];
var green = data[((sourceWidth * y) + x) * 4 + 1];
var blue = data[((sourceWidth * y) + x) * 4 + 2];
for (var n = 0; n < pix; n++) {
for (var m = 0; m < pix; m++) {
if (x + m < sourceWidth) {
data[((sourceWidth * (y + n)) + (x + m)) * 4] = red;
data[((sourceWidth * (y + n)) + (x + m)) * 4 + 1] = green;
data[((sourceWidth * (y + n)) + (x + m)) * 4 + 2] = blue;
}
}
}
}
}
context.putImageData(imageData, destX, destY);
}