forked from vegard/pwman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwman.js
82 lines (67 loc) · 2.38 KB
/
pwman.js
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
/*
JavaScript Password Manager — Copyright (C) 2011 Vegard Nossum
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
window.onload = function () {
/* Only show the contents of hidden fields when they are active (i.e.
* being edited). This is done to prevent peeking, etc. We could make
* the input fields be password fields, but in this case it is really
* important for the user to know what he/she is typing, since they
* REALLY want to enter the same values next time. */
$('form .hidden')
.fadeTo(0, 0)
.focusin(function (e) {
$(this).fadeTo('fast', 1);
})
.focusout(function (e) {
$(this).fadeTo('fast', 0);
});
$('#account .text :input')
/* Make sure that whenever an input field is changed, the current
* password is discarded (to prevent the user from using the wrong
* password). */
.change(function (e) {
$('#password').hide('fast');
$('#password span').text('');
})
/* Turn the textfield red if there were any spaces at the
* beginning or end of the input, or if there were two or
* more spaces in a row. */
.keyup(function (e) {
var val = $(this).val();
if (val === $.trim(val) && val.indexOf(' ') === -1) {
$(this).removeClass('error');
} else {
$(this).addClass('error');
}
return true;
});
$('#account :submit').click(function () {
var key = [
$.trim($('#passphrase').val()),
$.trim($('#tag').val())
];
var hash = $.sha256bin(key.join('-'));
var password = $.base64Encode(hash);
$('#password span').text(password.substr(0, 16));
$('#password').show('fast');
/* Prevent the form data from being submitted */
return false;
});
$('#help').click(function() {
$('#help-text').toggle('fast');
return false;
});
$('#password').hide();
$('#help-text').hide();
$('#passphrase').focus();
}