Advertisement
jcunews

Password Generator bookmarklet

Mar 8th, 2022
1,578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript:/*Password Generator*/
  2.   ((g, n, l, u, s, c, f, e) => {
  3.     while (true) {
  4.       if ((g = prompt("Please enter the number of characters to generate.", 15)) === null) return;
  5.       if (isNaN(g = parseInt(g)) || (g <= 0)) {
  6.         alert("Input must be a positive integer number.")
  7.       } else break
  8.     }
  9.     n = "0123456789";
  10.     u = (l = "abcdefghijklmnopqrstuvwxyz").toUpperCase();
  11.     s = "!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~";
  12.     c = {
  13.       "Numbers": n,
  14.       "Numbers & Lowercase Alphabets": n + l,
  15.       "Numbers & Upperercase Alphabets": n + u,
  16.       "Numbers & Alphabets": n + l + u,
  17.       "Numbers & Symbols": n + s,
  18.       "Numbers & Alphabets & Symbols": n + l + u + s,
  19.       "Lowercase Alphabets": l,
  20.       "Lowercase Alphabets & Symbols": l + s,
  21.       "Upperercase Alphabets": u,
  22.       "Upperercase Alphabets & Symbols": l + s,
  23.       "Alphabets": l + u,
  24.       "Alphabets & Symbols": l + u + s,
  25.       "Symbols": s
  26.     };
  27.     f = (o, a, i, r) => {
  28.       (a = []).length = g;
  29.       for (i = 0; i < g; i++) a[i] = o[1][(Math.random() * o[1].length) << 0];
  30.       e.textContent = a.join("");
  31.       return `<tr><td>${o[0]}</td><td>${e.innerHTML}</td></tr>`
  32.     };
  33.     (e = document.createElement("DIV")).id = "pgbookmarklet";
  34.     e.innerHTML = `<style>
  35. #pgbookmarklet,#pgbookmarklet *{all:revert}
  36. #pgbookmarklet{position:fixed;left:0;top:0;right:0;bottom:0;background:rgb(0,0,0,.5);cursor:pointer;font:14pt/normal sans-serif}
  37. #pgbookmarklet table{transform:translateY(10%);margin:auto;border-radius:.6em;border-spacing:.3em;padding:.3em;background:#fff;cursor:auto}
  38. #pgbookmarklet tr:nth-child(2n+1){background:#ddf}
  39. #pgbookmarklet td{padding:.3em}
  40. </style><table>${Object.entries(c).map(f).join("\n")}</table>`;
  41.     document.documentElement.insertAdjacentHTML("beforeend", e.outerHTML);
  42.     pgbookmarklet.onclick = e => (e.target === pgbookmarklet) && pgbookmarklet.remove()
  43.   })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement