summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/UI/Common/Components/PasswordEntropyDisplay.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Common/Components/PasswordEntropyDisplay.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/UI/Common/Components/PasswordEntropyDisplay.js140
1 files changed, 140 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Common/Components/PasswordEntropyDisplay.js b/frontend/gamma/js/Clipperz/PM/UI/Common/Components/PasswordEntropyDisplay.js
new file mode 100644
index 0000000..c1b4f13
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/UI/Common/Components/PasswordEntropyDisplay.js
@@ -0,0 +1,140 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27*/
28
29Clipperz.Base.module('Clipperz.PM.UI.Common.Components');
30
31Clipperz.PM.UI.Common.Components.PasswordEntropyDisplay = function(anElement, args) {
32 args = args || {};
33
34//MochiKit.Logging.logDebug(">>> new TextFormField");
35 Clipperz.PM.UI.Common.Components.PasswordEntropyDisplay.superclass.constructor.call(this, anElement, args);
36
37 this._wrapperElement = null;
38 this._entropyElement = null;
39
40 this.render();
41//MochiKit.Logging.logDebug("<<< new TextFormField");
42
43 return this;
44};
45
46Clipperz.Base.extend(Clipperz.PM.UI.Common.Components.PasswordEntropyDisplay, Clipperz.PM.UI.Common.Components.BaseComponent, {
47
48 'toString': function() {
49 return "Clipperz.PM.UI.Common.Components.PasswordEntropyDisplay";
50 },
51
52 //-----------------------------------------------------
53
54 'wrapperElement': function() {
55 return this._wrapperElement;
56 },
57
58 'setWrapperElement': function(aValue) {
59 this._wrapperElement = aValue;
60 },
61
62 //-----------------------------------------------------
63
64 'passwordElement': function() {
65 return this.element();
66 },
67
68 //-----------------------------------------------------
69
70 'entropyElement': function() {
71 return this._entropyElement;
72 },
73
74 'setEntropyElement': function(aValue) {
75 this._entropyElement = aValue;
76 },
77
78 //-----------------------------------------------------
79
80 'render': function() {
81/*
82 MochiKit.Signal.disconnectAllTo(this);
83
84 this.setWrapperElement(this.element().wrap({tag:'div'}));
85 this.setEntropyElement(Clipperz.DOM.Helper.append(this.wrapperElement().dom, {tag:'div', cls:'passwordEntropy', html:"&nbsp;"}, true));
86 // this.setEntropyElement(Clipperz.DOM.Helper.insertBefore(this.element(), {tag:'div', cls:'passwordEntropy', html:"&nbsp;"}, true));
87 this.entropyElement().wrap({tag:'div', cls:'passwordEntropyWrapper'});
88
89 this.updateEntropyElement();
90
91 this.connect('onkeyup', 'updateEntropyElement');
92 this.connect('onchange', 'updateEntropyElement');
93 this.connect('onblur', 'updateEntropyElement');
94*/
95 MochiKit.Signal.disconnectAllTo(this);
96
97 this.setEntropyElement(this.element());
98 this.entropyElement().addClass("entropyLevelIndicator");
99
100 this.updateEntropyElement();
101
102 this.connect('onkeyup', 'updateEntropyElement');
103 this.connect('onchange', 'updateEntropyElement');
104 this.connect('onblur', 'updateEntropyElement');
105 },
106
107 //-----------------------------------------------------
108
109 'computeEntropyForString': function(aValue) {
110 return Clipperz.PM.Crypto.passwordEntropy(aValue);
111 },
112
113 //-----------------------------------------------------
114
115 'updateEntropyElement': function(anEvent) {
116/*
117//MochiKit.Logging.logDebug(">>> PasswordEntropyDisplay.updateEntropyElement");
118 varmaxExtent;
119 varentropy;
120
121 entropy = Math.min(128, this.computeEntropyForString(this.passwordElement().dom.value));
122//MochiKit.Logging.logDebug("--- PasswordEntropyDisplay.updateEntropyElement - entropy: " + entropy);
123 this.entropyElement().setStyle('background-position', "0px " + -entropy + "px");
124 this.entropyElement().setWidth(this.passwordElement().getWidth() * (entropy/128));
125//MochiKit.Logging.logDebug("<<< PasswordEntropyDisplay.updateEntropyElement");
126*/
127 varentropy;
128
129 entropy = Math.min(128, this.computeEntropyForString(this.passwordElement().dom.value));
130
131 if (entropy == 0) {
132 this.entropyElement().setStyle('background-position', "0px 26px");
133 } else {
134 this.entropyElement().setStyle('background-position', "0px -" + (128-entropy)*26 + "px");
135 }
136 },
137
138 //-----------------------------------------------------
139 __syntaxFix__: '__syntaxFix__'
140});