-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
163 lines (147 loc) · 6.96 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
<!DOCTYPE html>
<html lang="en-GB">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap icons 1.11.3 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css" integrity="sha384-tViUnnbYAV00FLIhhi3v/dWt3Jxw4gZQcNoSCxCIFNJVCx7/D55/wXsrNIRANwdD" crossorigin="anonymous">
<!-- Bootstrap CSS 5.1.3 -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script type="application/javascript">
function generatePassword() {
/*
Password will always include numbers and letters.
Symbols are optionals.
*/
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
letters = ["a", "b", "c", "d", "e", "f", "g", "h","i","j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "y", "z"]
upperCaseLetters = letters.map(element => {return element.toUpperCase();});
symbols = ["@", "#", "$", "%", "!", "&", "=", "*", "+", "-", "_"]
range = document.getElementById('password-range-output').value;
range = range === "" ? 32 : range;
includeSymbols = document.getElementById('include-symbols').checked;
possibleSetOfValues = includeSymbols ? [numbers, letters, upperCaseLetters, symbols] : [numbers, letters, upperCaseLetters];
password = "";
for (let i = 0; i < range; i++) {
selectedSetRandom = randomNumberFromZeroToLength(possibleSetOfValues.length);
selectedSet = possibleSetOfValues[selectedSetRandom]
selectedCharacterRandom = randomNumberFromZeroToLength(selectedSet.length);
passwordValue = selectedSet[selectedCharacterRandom];
password += passwordValue;
}
document.getElementById('password-generated').value = password;
changeCopyButtonTextToCopy();
}
function randomNumberFromZeroToLength(length) {
return Math.floor(Math.random() * length);
}
function copyToClipboard() {
/* Get the text field */
var copyText = document.getElementById("password-generated");
/* Select the text field */
copyText.select();
/* For mobile devices */
copyText.setSelectionRange(0, 99999);
/* Copy the text inside the text field */
navigator.clipboard.writeText(copyText.value);
changeCopyButtonTextToCopied();
}
function changeCopyButtonTextToCopy() {
var currentValue = document.getElementById("copy-button").innerHTML;
if (currentValue !== "copy") {
document.getElementById("copy-button").innerHTML = "copy";
}
}
function changeCopyButtonTextToCopied() {
document.getElementById("copy-button").innerHTML = "copied!";
}
function setDefaultValueToPasswordRangeOutput(){
document.getElementById('password-range-output').value = 32;
}
</script>
<style type="text/css">
a {text-decoration: none;}
</style>
<link rel="icon" type="image/x-icon" href="https://github.com/w0rmr1d3r.png">
<title>passwrd - strong password generator</title>
</head>
<body onload="generatePassword();setDefaultValueToPasswordRangeOutput();">
<nav class="navbar navbar-light bg-light">
<div class="container-fluid">
<span class="navbar-brand mb-0 h1">passwrd</span>
</div>
</nav>
<br>
<div class="container">
<div class="row">
<div class="col">
<h3>Password range</h3>
</div>
</div>
<br>
<div class="row">
<div class="col"></div>
<div class="col-8 input-group">
<p class="form-label">Selected range: </p>
<output id="password-range-output"></output>
<input type="range" class="form-range" value="32" min="8" max="128" oninput="this.previousElementSibling.value=this.value" onchange="generatePassword()">
</div>
<div class="col"></div>
</div>
<br>
<div class="row">
<div class="col">
<h3>Other options</h3>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-check form-switch">
<label class="form-check-label" for="include-symbols">Include symbols</label>
<input class="form-check-input" type="checkbox" id="include-symbols" checked onchange="generatePassword()">
</div>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col"></div>
<div class="col-8 input-group">
<input class="form-control" type="text" id="password-generated" aria-label="password-generated" readonly>
<button class="btn btn-outline-secondary" type="button" id="copy-button" onclick="copyToClipboard()">copy</button>
</div>
<div class="col"></div>
</div>
<br>
<div class="row">
<div class="d-flex justify-content-center">
<button type="button" class="btn btn-success" onclick="generatePassword()">Generate password</button>
</div>
</div>
</div>
<footer class="container-fluid fixed-bottom">
<div class="d-flex justify-content-center">
<address>
<h6>
<a href="https://github.com/sponsors/w0rmr1d3r">sponsor me <i class="bi bi-piggy-bank-fill"></i></a>
  -  
<a href="https://buymeacoffee.com/w0rmr1d3r">buy me a coffee <i class="bi bi-cup-hot-fill"></i></a>
</h6>
</address>
</div>
<div class="d-flex justify-content-center">
<address>
<h6>
<a href="https://github.com/w0rmr1d3r/passwrd">w0rmr1d3r <i class="bi bi-github"></i></a>
</h6>
</address>
</div>
</footer>
<!-- Bootstrap Bundle with Popper 5.1.3 -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<!-- 100% privacy-first analytics -->
<script async defer src="https://scripts.simpleanalyticscdn.com/latest.js" integrity="sha384-6r8ANWkTbGeAoBOxTtwsJD6VBfqnKe+kD3q/w51t91jCOCSxtKcCN2erSIv/1GHO"></script>
<noscript><img src="https://queue.simpleanalyticscdn.com/noscript.gif" alt="" referrerpolicy="no-referrer-when-downgrade" /></noscript>
</body>
</html>