-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
157 lines (137 loc) · 6 KB
/
index.html
File metadata and controls
157 lines (137 loc) · 6 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
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>indiko</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html {text-align: center; zoom: 160%;}
p {font-size: 80%;}
</style>
</head>
<body>
<p><a href="https://github.com/ferfebles/indiko"
style='font-size:150%'>indiko</a><br>the amnesic pwd manager</p>
<div>
<input type="password" id="mstrpwd"
onkeyup="enableWithLength(this, 16, 'account')"
placeholder="m4ster pwd (size>15)" autofocus disabled>
</div>
<div>
<input type="text" id="account"
onkeyup="enableWithLength(this, 4, 'dat3s')"
placeholder="anyaccount@eg.gmail" disabled>
</div>
<br>
<div id="dat3s">
<div>
<button onclick="updateLabel(this)" disabled
id="last_year" style='color: grey'>1969</button>
<button onclick="updateLabel(this)" disabled
id="current_year">1970</button>
<button onclick="updateLabel(this)" disabled
id="next_year" style='color: grey'>1971</button>
</div>
<div>
<button onclick="updateLabel(this)" disabled id="q1">Q1</button>
<button onclick="updateLabel(this)" disabled id="q2">Q2</button>
<button onclick="updateLabel(this)" disabled id="q3">Q3</button>
<button onclick="updateLabel(this)" disabled id="q4">Q4</button>
</div>
</div>
<br>
<div id="notice" style='font-size:75%'>enable javascript, please</div>
<div id="pwd" style='font-size:45%'></div>
<script>
var currentYear = (new Date()).getFullYear()
// Base64 encode
function encode64 (buff) {
return btoa(new Uint8Array(buff)
.reduce((s, b) => s + String.fromCharCode(b), ''))
}
function selectChar (fromString, withChar) {
return fromString[(withChar.charCodeAt() % fromString.length)]
}
function fulfilPWDRequirements (pwd) {
var lowerCase = 'abcdefghijklmnopqrstuvwxyz'
var upperCase = lowerCase.toUpperCase()
var digits = '0123456789'
var symbols = '!@#%&=_:,;<>$|.+/'
return selectChar(lowerCase, pwd[0]) +
selectChar(upperCase, pwd[1]) +
selectChar(digits, pwd[2]) +
selectChar(symbols, pwd[3]) +
pwd.substring(4)
}
function str2ArrBuff (string) {
var encoder = new TextEncoder('utf-8')
return encoder.encode(string)
}
function enableWithLength (e, minLength, id) {
var i
var newDisabledValue = (e.value.length < minLength)
var elements = document.getElementById(id).querySelectorAll('*')
document.getElementById(id).disabled = newDisabledValue
for (i = 0; i < elements.length; i++) {
elements[i].disabled = newDisabledValue
}
}
function copyPBKDF2 (rawKey, salt, button) {
crypto.subtle.importKey('raw', str2ArrBuff(rawKey),
'PBKDF2', false, ['deriveBits'])
.then(baseKey => {
return crypto.subtle.deriveBits(
{name: 'PBKDF2',
salt: str2ArrBuff(salt),
iterations: 100000,
hash: 'sha-512'},
baseKey,
192)
})
.then(result => {
var pwd = fulfilPWDRequirements(encode64(result))
if (navigator.clipboard) {
navigator.clipboard.writeText(pwd).then(function () {
document.getElementById('notice').textContent =
'pwd for ' + button + ' copied'
})
} else {
document.getElementById('notice').textContent =
'pwd for ' + button
document.getElementById('pwd').textContent = pwd
}
})
.catch(err => { alert('Key derivation failed: ' + err.message) })
}
function updateLabel (e) {
if (e.id === 'last_year') { currentYear-- }
if (e.id === 'next_year') { currentYear++ }
copyPBKDF2((document.getElementById('mstrpwd').value),
(document.getElementById('account').value +
e.textContent + currentYear.toString()),
e.textContent)
updateDateButtons()
}
function updateDateButtons () {
document.getElementById('last_year').textContent =
(currentYear - 1).toString()
document.getElementById('current_year').textContent =
currentYear.toString()
document.getElementById('next_year').textContent =
(currentYear + 1).toString()
}
function initChecks () {
var noticeHtml = ''
document.getElementById('mstrpwd').disabled = false
updateDateButtons()
if (!(window.crypto && crypto.subtle)) {
noticeHtml = 'Web Crypto <a href="https://github.com/ferfebles/indiko#but">not supported</a>!'
} else if (!(navigator.clipboard)) {
noticeHtml = 'Clipboard <a href="https://github.com/ferfebles/indiko#but">not supported</a>!'
}
document.getElementById('notice').innerHTML = noticeHtml
}
initChecks()
</script>
</body>
</html>