Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

Commit cd50d31

Browse files
committed
v0.2 release with support for Salts and minimum character length
1 parent 64135c1 commit cd50d31

File tree

4 files changed

+80
-55
lines changed

4 files changed

+80
-55
lines changed

History.markdown

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Chroma-Hash Version History
2+
===========================
3+
4+
## Version 0.2 [2009-8-4]
5+
6+
- [New] Salt: Added parameter for salt to be applied for hash function
7+
- [New] Grayscale: Added parameter to specify minimum number of characters of input needed for colors to appear. Under that length, bars appear in grayscale.
8+
- [Bugfix] "Color change effects pause on lost focus" (mikehamer)
9+
- [Changed] Tag-line is now "A sexy, secure visualization of password field input"
10+
11+
## Version 0.1
12+
13+
Initial release.

README.markdown

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Chroma-Hash
22
===========
33

4-
## A sexy, non-reversable live visualization of password field input
4+
## A sexy, secure visualization of password field input
55

66
*In a tweet*: Chroma-Hash is a jQuery plugin that dynamically visualizes secure text-field values using ambient color bars
77

@@ -17,10 +17,12 @@ Try it out at: <tt>[http://mattt.github.com/Chroma-Hash/](http://mattt.github.co
1717
## Usage
1818

1919
<code>
20-
$("input:password").chromaHash({number: 3});
20+
$("input:password").chromaHash({bars: 3, salt:"7be82b35cb0199120eea35a4507c9acf", minimum:6});
2121
</code>
2222

23-
- <tt>number</tt> parameter controls the number of bars displayed (1,2,3, or 4)
23+
- <tt>bars</tt> number of bars displayed (1,2,3, or 4)
24+
- <tt>salt</tt> value to be appended when calculating hash function
25+
- <tt>minimum</tt> minimum number of characters needed for grayscale bars to be displayed in color
2426

2527
## Requirements
2628
- jQuery 1.3+

chroma-hash.js

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,52 +36,54 @@
3636
return $(this).attr('for') == id;
3737
});
3838
};
39+
40+
var trigger = function(e) {
41+
if($(this).val() == "" ){
42+
chromaHashesForElement(this).animate({backgroundColor: "#ffffff"});
43+
return;
44+
}
45+
46+
height = $(this).height();
47+
position = $(this).position();
48+
width = $(this).outerWidth();
49+
50+
chromaHashesForElement(this).each(function(i) {
51+
$(this).css({position: 'absolute',
52+
left: position.left + width - 2,
53+
top: position.top,
54+
height: height + "px",
55+
width: 8 + "px",
56+
margin: 5 + "px",
57+
marginLeft: -8 * (i + 1) + "px"
58+
});
59+
});
60+
61+
var id = $(this).attr('id');
62+
var md5 = hex_md5('' + $(this).val() + ':' + o.salt);
63+
var colors = md5.match(/([\dABCDEF]{6})/ig);
64+
$(".chroma-hash").stop();
65+
66+
if($(this).val().length < o.minimum) {
67+
chromaHashesForElement(this).each(function(i) {
68+
var g = (parseInt(colors[i], 0x10) % 0xF).toString(0x10);
69+
$(this).animate({backgroundColor:"#" + g + g + g});
70+
});
71+
}
72+
else {
73+
chromaHashesForElement(this).each(function(i) {
74+
$(this).animate({backgroundColor:"#" + colors[i]});
75+
});
76+
}
77+
};
3978

4079
obj.each(function(e) {
4180
for(c in colors) {
4281
$(this).after('<label for="' + $(this).attr('id') + '" class="' + colors[c] + ' chroma-hash"></label>');
4382
}
4483

45-
$(this).keyup(function(e){
46-
if($(this).val() == "" ){
47-
chromaHashesForElement(this).animate({backgroundColor: "#ffffff"});
48-
return;
49-
}
50-
51-
height = $(this).height();
52-
position = $(this).position();
53-
width = $(this).outerWidth();
54-
55-
chromaHashesForElement(this).each(function(i) {
56-
$(this).css({position: 'absolute',
57-
left: position.left + width - 2,
58-
top: position.top,
59-
height: height + "px",
60-
width: 8 + "px",
61-
margin: 5 + "px",
62-
marginLeft: -8 * (i + 1) + "px"
63-
}
64-
);
65-
});
66-
67-
var id = $(this).attr('id');
68-
var md5 = hex_md5('' + $(this).val() + ':' + o.salt);
69-
var colors = md5.match(/([\dABCDEF]{6})/ig);
70-
$(".chroma-hash").stop();
71-
72-
if($(this).val().length < o.minimum) {
73-
chromaHashesForElement(this).each(function(i) {
74-
var g = (parseInt(colors[i], 0x10) % 0xF).toString(0x10);
75-
$(this).animate({backgroundColor:"#" + g + g + g});
76-
});
77-
}
78-
else {
79-
chromaHashesForElement(this).each(function(i) {
80-
$(this).animate({backgroundColor:"#" + colors[i]});
81-
});
82-
}
83-
});
84-
});
84+
$(this).bind('keyup', trigger);
85+
$(this).bind('blur', trigger);
86+
});
8587

8688
/*
8789
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message

example.html

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<head>
66
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
77
<meta name="author" content="Mattt Thompson">
8-
<meta name="description" content="Chroma-Hash is a sexy, non-reversable live visualization of password field input">
8+
<meta name="description" content="Chroma-Hash is a sexy, secure visualization of password field input">
99
<title>Chroma-Hash Demo</title>
1010
<script src="http://www.google.com/jsapi"></script>
1111
<script type="text/javascript" charset="utf-8">
@@ -15,18 +15,18 @@
1515
<script src="chroma-hash.js" type="text/javascript" charset="utf-8"></script>
1616
<script type="text/javascript" charset="utf-8">
1717
$(document).ready(function() {
18-
$("input:password").chromaHash({number: 3});
18+
$("input:password").chromaHash({bars: 3});
1919
$("#username").focus();
2020
});
2121
</script>
2222
<style type="text/css" media="screen">
2323
body{background:#ddd;font-size:1.3em;font-family:"Helvetica",Helvetica,sans-serif;}
2424
h1,h2{text-align:center;}
2525
h1{color:#222;text-shadow:1px 1px 1px #ddd;margin-bottom:0.5em;}
26-
h2{color:#888;width:70%;margin:0.5em auto 30px auto;font-family:"Palantino",Georgia;font-size:80%;font-style:italic;font-weight:normal;}
27-
p,label{text-shadow:1px 1px 1px #f2f2f2;}
26+
h2{color:#888;width:80%;margin:0.5em auto 30px auto;font-family:"Palantino",Georgia;font-size:80%;font-style:italic;font-weight:normal;}
27+
p,label, span{text-shadow:1px 1px 1px #f2f2f2;}
2828
label{color:#444;display:block;font-variant:small-caps;text-transform:lowercase;}
29-
p{font-size:87%;color:#444;}
29+
p{font-size:77%;color:#444;}
3030
input{width:440px;font-size:1.5em;margin-bottom:0.75em;}
3131
.explanation{text-align:center;}
3232
a{color:#444;}
@@ -35,30 +35,38 @@
3535
a:active{color:#fff;background:#444;text-shadow:none;}
3636
fieldset{width:440px;margin:10px auto;border:none;}
3737
hr{border:0px transparent solid;border-top:1px #fdfdfd solid;border-bottom:1px #ddd solid;margin:20px 0 30px 0;}
38-
.container{padding:30px;width:480px;margin:100px auto;background:#fff;-moz-border-radius:11px;-khtml-border-radius:11px;-webkit-border-radius:11px;border-radius:11px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;-webkit-box-shadow:1px 0px 5px #666;-khtml-box-sizing:content-box;box-sizing:content-box;
38+
.container, .footer{width:480px;}
39+
.container{padding:30px 30px;margin:100px auto 30px auto;background:#fff;-moz-border-radius:11px;-khtml-border-radius:11px;-webkit-border-radius:11px;border-radius:11px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;-webkit-box-shadow:1px 0px 5px #666;-khtml-box-sizing:content-box;box-sizing:content-box;
3940
}
41+
.footer{margin:0 auto;display:block;color:#555;text-align:center;font-size:0.6em;}
42+
.footer span{display:block;line-height:1.5em;}
4043
</style>
4144
</head>
4245

4346
<body>
47+
<a href="http://github.com/mattt/Chroma-Hash/">
48+
<img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" />
49+
</a>
4450
<div class="container">
4551
<h1>Chroma-Hash</h1>
46-
<h2>a sexy, non-reversible live visualization of password field input</h2>
52+
<h2>a sexy, secure visualization of password field input</h2>
4753
<fieldset>
4854
<label>Username</label>
4955
<input type="text" name="username" value="" id="username">
50-
5156
<label>Password</label>
5257
<input type="password" name="password" value="" id="password">
53-
5458
<label>Confirm Password</label>
5559
<input type="password" name="confirm-password" value="" id="confirm-password">
5660
</fieldset>
57-
5861
<hr/>
5962
<div class="explanation">
60-
<p>Learn more and fork it for yourself at <tt><a href="http://github.com/mattt/Chroma-Hash/">http://github.com/mattt/Chroma-Hash/</a></tt></p>
63+
<p>Looking for some more explanation? Have some feedback?<br/>Check out <a href="http://mattt.me/2009/07/chroma-hash-a-belated-introduction/">my blog post about Chroma-Hash</a></p>
6164
</div>
6265
</div>
66+
<div class="footer">
67+
<span class="copyright">&copy; <a href="http://twitter.com/mattt" title="@mattt" rel="me">Mattt Thompson</a> - Released Under an MIT License</span>
68+
<span class="version">Last Revised: August 4, 2009</span>
69+
</div>
70+
6371
</body>
64-
</html>
72+
</html>

0 commit comments

Comments
 (0)