-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneratePassword.html
More file actions
107 lines (88 loc) · 2.86 KB
/
generatePassword.html
File metadata and controls
107 lines (88 loc) · 2.86 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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="less.css">
<style type="text/css">
input,
textarea {
font-family: monospace;
font-size: 24px;
}
</style>
<script type="text/javascript">
function uuidv4() {
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);
}
function genPassword() {
const input = document.getElementsByName('length')[0];
const len = parseInt(input.value, 10);
const s = 'ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789';
let r = '';
for (let i = 0; i < len; ++i) {
const idx = crypto.getRandomValues(new Uint8Array(1))[0] % s.length;
r += s.charAt(idx);
}
return r;
}
function genMulti(rand) {
const result = document.getElementsByName('result')[0];
result.value = rand();
const list = document.getElementsByName('list')[0];
let m = '';
for (let i = 0; i < 10; ++i) {
m += rand() + '\n';
}
list.value = m;
}
function onSubmit(e) {
e.preventDefault();
const submitValue = e.submitter.value;
if ('GenerateUuidV4' === submitValue) {
genMulti(uuidv4);
} else {
genMulti(genPassword);
}
return false;
}
function onLoad() {
const form = document.getElementsByName('form')[0];
form.onsubmit = onSubmit;
const length = document.getElementsByName('length')[0];
length.onchange = function (e) {
e.preventDefault();
genMulti(genPassword);
return false;
}
const result = document.getElementsByName('result')[0];
result.onfocus = function (e) {
e.preventDefault();
e.target.select();
document.execCommand("copy");
};
genMulti(genPassword);
}
window.addEventListener("load", onLoad);
</script>
</head>
<body class="generatePassword">
<div class="wrap">
<h1>nativebinary - generatePassword</h1>
<h4>
<a href="https://nativebinary.github.io/json-util/">jsonPrettier</a> |
<a href="https://nativebinary.github.io/json-util/jsonToJava.html">jsonToJava</a> |
<a href="https://nativebinary.github.io/json-util/ddlToJava.html">ddlToJava</a> |
<a href="https://nativebinary.github.io/json-util/generatePassword.html">generatePassword</a> |
<a href="https://nativebinary.github.io/json-util/mybatisBind.html">mybatisBind</a> |
</h4>
<form name="form" onsubmit="return false;">
<input type="number" name="length" value="16" size="5">
<input type="submit" value="GeneratePassword">
<input type="submit" value="GenerateUuidV4">
</form>
<input type="text" name="result" size="50" /><br />
<textarea name="list" cols="50" rows="15"></textarea>
</div>
</body>
</html>