-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
244 lines (231 loc) · 9.77 KB
/
index.html
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags always come first -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<style>
.bg {
background-image: url(background1.jpg);
background-position: 0% 25%;
background-size: cover;
background-repeat: no-repeat;
}
.icon {
width: 16px;
height: 16px;
margin-bottom:2px
}
.display-3 {
font-size: 4rem;
font-weight: 400;
}
.lead {
font-size: 1.25rem;
font-weight: 400;
}
.jumbotron {
padding: 1rem 0rem;
margin-bottom: 1rem;
}
</style>
</head>
<body>
<div class="jumbotron jumbotron-fluid bg">
<div class="container">
<h1 class="display-3">PASSWRD</h1>
<p class="lead">Promise, it's really super easy and secure! If you don't know what to do, <a href="help.html">here</a> you get further instructions</p>
<p>
<a class="btn btn-primary btn-lg" href="help.html" role="button">Learn more</a>
</p>
</div>
</div>
<div class="container">
<form role="form" autocomplete="off">
<div class="form-group">
<label for="mMaster">Masterkey</label>
<div class="input-group">
<input type="password" class="form-control" id="mMaster" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" placeholder="your super secret master password">
<div class="input-group-append">
<div class="input-group-text" id="mCheck" title="remember the hashcode of masterpassword" >hash</div>
</div>
<div class="input-group-append">
<div class="input-group-text" id="mToggle" title="show masterpassword">toggle</div>
</div>
</div>
</div>
<div class="form-group">
<label for="mUsername">Username</label>
<input type="text" class="form-control" id="mUsername" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" placeholder="e.g. testuser or [email protected]">
</div>
<div class="form-group">
<label for="mDomain">Domain</label>
<input type="text" class="form-control" id="mDomain" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
placeholder="e.g. heise.de or google.com">
</div>
<div class="form-group" style="display:None" id="dCounter">
<label for="mCounter">Counter</label>
<input type="number" class="form-control" id="mCounter" value="1" min="1" max="99">
</div>
<div class="form-group" style="display:None" id="dLength">
<label for="mLength">Length</label>
<input type="number" class="form-control" id="mLength" value="12" min="4" max="32">
</div>
<div class="form-group" style="display:None" id="dSep">
<label for="mPattern">Password Format</label>
<select class="form-control" id="mSep">
<option value="3" selected="">Apple style passwords with dashes</option>
<option value="0" >Just a bunch of char</option>
</select>
</div>
<div class="form-group" style="display:None" id="dPattern">
<label for="mPattern">Allowed Characters</label>
<select class="form-control" id="mPattern">
<option value="0">A-Za-z0-9!@#$%&*?</option>
<option value="1" selected="">A-Za-z0-9</option>
<option value="2">PIN</option>
</select>
</div>
<div class="form-group">
<button type="button" class="btn btn-secondary clearfix " onclick="toggle_options()">
<img src="svg/chevron-bottom.svg" alt="expand" class="icon pull-left" id="bOptions"/>
Options
</button>
<button type="button" class="btn btn-primary" onclick="generate()">Generate</button>
</div>
<div class="form-group" id="result" style="display:None">
<label for="passwrd">Domain password</label>
<div class="input-group">
<input type="text" class="form-control" id="passwrd" autocomplete="off" disabled
style="font-family: Monospace">
<span class="input-group-btn">
<button class="btn btn-info" type="button" onclick="copy_to_clipboard()">
Copy Clipboard
</button>
</span>
</div>
</div>
</form>
</div>
<!-- jQuery first, then Tether, then Bootstrap JS. -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="js/sha256.js"></script>
<script type="text/javascript">
var template = ["ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*?abcdefghjklmnopqrstuvwxyz0123456789!@#$%&*?",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghjklmnopqrstuvwxyz0123456789",
"0123456789"];
var enter = false;
function calculate(master, username, domain, counter, length, template, sep) {
var key = master + ":" + domain.toLowerCase() + ":" + username.toLowerCase() + ":" + counter
var hashed_key = Sha256.hash(key, { outFormat: 'hex' })
console.log("hashed key:" + hashed_key);
length *= 2 // duplicate length because we are using 2 char
var result = ""
for (i = 0; i < hashed_key.length ; i=i+2) {
if (i==length) {
break
}
k = parseInt(hashed_key[i] + hashed_key[i+1], 16)
kk = k % template.length
console.log(k + ":"+kk + ":" + template[kk] )
result += template[kk]
}
if (sep > 0) {
var tmp = result.match(new RegExp('.{1,' + sep + '}', 'g'));
result = tmp.join('-')
}
console.log("generated password: " + result)
return result
}
function generate() {
var master = $("#mMaster").val();
if (master=="") {
$("#mMaster").addClass("bg-warning text-white")
$("#result").hide();
return
} else {
$("#mMaster").removeClass("bg-warning text-white")
}
var username = $("#mUsername").val();
var domain = $("#mDomain").val();
var counter = $("#mCounter").val();
var length = $("#mLength").val();
var pattern = parseInt($('#mPattern').val());
var sep = parseInt($('#mSep').val());
pwd = calculate(master, username, domain, counter, length, template[pattern], sep)
$("#passwrd").val(pwd);
$("#result").show();
//$("html, body").animate({ scrollTop: $(document).height() }, "slow");
window.scrollTo(0,1000)
}
function toggle_options() {
if($('#mLength').css('display') == 'none') {
$("#bOptions").attr("src","svg/chevron-top.svg");
} else {
$("#bOptions").attr("src","svg/chevron-bottom.svg");
}
$("#dCounter").toggle();
$("#dLength").toggle();
$("#dPattern").toggle();
$("#dSep").toggle();
}
function hashCode(data) {
var hash = 0, i, chr;
if (data.length === 0) return hash;
for (i = 0; i < data.length; i++) {
chr = data.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
function reset() {
//window.alert("purge")
$("#mMaster").val('');
$("#mUsername").val('')
$("#mDomain").val('');
$("#passwrd").val('');
$("#mCounter").val('1');
$("#mLength").val('12');
$("#mPattern").val(1);
$("#mSep").val(3);
$("#result").hide();
}
function copy_to_clipboard() {
window.prompt("Copy to clipboard: Ctrl+C, Enter", $("#passwrd").val());
}
// populate the document
$(document).ready(function () {
$('#mToggle').hover(function () {$('#mMaster').attr('type', 'text');},
function () {$('#mMaster').attr('type', 'password');});
$( "#mMaster" ).click(function() {
window.setTimeout(reset, 600000);
});
$( "#mMaster" ).keyup(function() {
tmp = $("#mMaster").val();
tmp = hashCode(tmp)
tmp = tmp % 65535 // limit to small hash number
if (tmp < 0) tmp *= -1
$("#mCheck").text(tmp.toString(16));
});
// optimization for keyboard usage. First Enter generates Code, Second Enter opens Dialog for easier copy
$('#mDomain').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
generate();
if (window.enter == false){
window.enter = true;
} else {
copy_to_clipboard();
}
};
});
});
</script>
</body>
</html>