Last active
March 21, 2023 23:14
-
-
Save piyush01123/265c95fcd809a8f7543b001da8e6e9da to your computer and use it in GitHub Desktop.
Generate and copy to clipboard strong password - Tampermonkey script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Generate Strong Password | |
// @namespace http://tampermonkey.net/ | |
// @version 3.1.1 | |
// @description Strong password generator of size 12 | |
// @author Piyush Singh | |
// @match *://*/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant unsafeWindow | |
// @grant GM_setClipboard | |
// ==/UserScript== | |
// To Use just press Ctrl+G and you will have a strong password in your clipboard. | |
// Can also be used from your browser console by `genpwd()` | |
// Fisher Yates algorithm to shuffle an array and return first n elements | |
function fisherYates(arr, n) | |
{ | |
var i = arr.length; | |
while (i--) | |
{ | |
var idx = Math.floor(i * Math.random()); | |
[arr[i],arr[idx]] = [arr[idx],arr[i]]; | |
} | |
return arr.slice(0,n); | |
} | |
function genpwd() | |
{ | |
var lowercase = "abcdefghijlmnopqrstuvwxyz"; | |
var uppercase = "ABCDEFGHIJLMNOPQRSTUVWXYZ"; | |
var digits = "0123456789"; | |
var punctuation = "#$%()*./:<=>?@|~"; | |
var low = fisherYates(lowercase.split(''),3); | |
var upp = fisherYates(uppercase.split(''),3); | |
var dig = fisherYates(digits.split(''),3); | |
var pun = fisherYates(punctuation.split(''),3); | |
var pwd = [].concat(low,upp,dig,pun); | |
pwd = fisherYates(pwd,12); | |
var password = pwd.join('') | |
return password; | |
} | |
(function() { | |
'use strict'; | |
if(!unsafeWindow.genpwd) unsafeWindow.genpwd = genpwd; | |
document.onkeyup=function(ev){ | |
// var ev = ev || window.event; // for IE to cover IEs window object | |
if(ev.ctrlKey && ev.which == 71) { | |
var password = genpwd(); | |
GM_setClipboard(password); | |
return false; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment